3.2 KiB
3.2 KiB
Hints
General
whileloops are used for indefinite (uncounted) iterationforloops are used for definite, (counted) iteration.- The keywords
breakandcontinuehelp customize loop behavior. range(<start>, stop, <step>)can be used to generate a sequence for a loop counter.- The built-in
enumerate()will return (<value>,<index>) pairs to iterate over.
Also being familiar with the following can help with completing the tasks:
lists: indexing, nested lists,<list>.append,<list>.pop().str:str()constructor, using the+to concatenate strings, optionally,f-strings.
1. Rounding Scores
Whileloops will continue to execute until their test condition evaluates toFalse.<list>.pop()will remove and return the last item in alist.- Empty lists evaluate to
False(most empty objects in Python are "Falsy")
2. Non-Passing Students
- There's no need to declare
loopcounters orindexcounters when iterating through an object using aforloop. - A results counter does need to be set up and incremented -- you'll want to
returnthe count of non-passing students when the loop terminates.
3. The "Best"
- There's no need to declare
loopcounters orindexcounters when iterating through an object using aforloop. - Having an empty
listto add the "best" marks to is helpful here. <list>.append()can help add things to the resultslist.
4. Calculating Letter Grades
- These are lower thresholds. The lower threshold for a "D" is a score of 41, since an "F" is <= 40.
range()can be helpful here to generate a sequence with the proper "F" -> "A" increments.round()without parameters should round off increments nicely.- As with "the best" task,
<list>.append()could be useful here to append items fromrange()into a resultslist.
5. Matching Names to Scores
enumerate()could be helpful here.- If both lists are the same length and sorted the same way, could you use the
indexfrom one to retrieve avaluefrom the other?
6. A "Perfect" Score
- There may be or may not be a student with a score of 100, and you can't return
[]without checking all scores. - The
control flowstatementscontinueandbreakmay be useful here to move past unwanted values.