-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Submitting examples for code review for python-break examples #634
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Changed variable names to use underscores, rather than camel-case
Breaking out of a while loop early. Code example prints out first five (or less) test scores.
Code example for getting user input
Nested loop example, which prints out the number of students who got at least one failed score
|
@acsany Hello! I made some edits and uploaded my updated code examples |
acsany
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @dphoenix!
Thanks for providing the code examples and creating the PR. Please have a look at my comments below 🙂
| # Use case 2: Print out the score of the first five tests (while loop) | ||
| scores = [90, 30, 50] | ||
| i = 0 | ||
|
|
||
| while i < 5: | ||
| if i > len(scores) - 1: | ||
| # If there are less than 5 scores, | ||
| # break out of the loop when all scores are printed | ||
| break | ||
| print("Score: " + str(scores[i])) | ||
| i += 1 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not a fan of this example. Generally, you'd instead use a for loop for this (like in the first example.)
| # Use case 2: Print out the score of the first five tests (while loop) | |
| scores = [90, 30, 50] | |
| i = 0 | |
| while i < 5: | |
| if i > len(scores) - 1: | |
| # If there are less than 5 scores, | |
| # break out of the loop when all scores are printed | |
| break | |
| print("Score: " + str(scores[i])) | |
| i += 1 | |
| # Use case 2: Check if a student passes an exam | |
| points = [10, 15, 3, 12, 14, 9] | |
| max_score = len(points) * 15 | |
| min_score_to_pass = max_score / 2 | |
| student_score = 0 | |
| for score in points: | |
| student_score += score | |
| if student_score >= min_score_to_pass: | |
| print("Congratulations, you passed the exam!") | |
| break |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@acsany Point taken. Do you think we should just take this one out? But regarding the suggested change, the task that the code performs from the user's perspective is different, but I don't know that the concept this amended code demonstrates is so different from use case #1. And since the user input example has a while-loop, we're meeting the intended original purpose of this example, which was to show a while/break combination. Would this updated use case example be redundant now?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good point! I'd say, let's keep this example out and only take it in if you feel you need another example to explain break.
Fixed a variable typo
- Changed True/False values to "Yes"/"No", to make output more reader-friendly - Used f-string for string interpolation
Used f-strings for string interpolation
Removed unnecessary nested loop
|
@acsany I need a little help with the linter. For my latest job, I got this message: Oh no! 💥 💔 💥 But I don't see anything indicating how I would need to fix this file. Can you help me understand what it's asking me to fix? Thanks so much! |
Created a more meaningful variable name
|
@acsany Created the pull request for my updated materials/code samples |
Where to put new files:
my-awesome-articleHow to merge your changes: