Nov-28-2020, 01:10 AM
@perfringo
This was an example mentioned in class and I think it's similar to I'm asked to do. I think instead of returning something I need to print something. But the loop information in between, I need to change the code for it to match mine to give instructions on what to do. I got lost in my code and I don't know what to input for the code in bold python.
Example from class:
We’ve seen that entries in a dictionary can be accessed using keys. In the same way,
items in a list can be accessed by index, the numerical position of the item, counting
the first position as 0, the next as 1 and so on. If papers is the list [17, 0, 8, 3, ..., 14],
then papers[0] is 17, papers[1] is 0 and so on, up through papers[29] which is 14. In
this example, the key fact is that papers[3] is 3, showing that Student 3 got his or her
own paper.
Once papers has been shuffled, the following code does the checking we want:
is 1 and so on. If a match is found, the function paperStatus immediately
stops—without finishing the for statement—and returns the answer 'warning'. If the
for statement completes, it must be because no match was found. In this case,
paperStatus returns 'okay'.
This was an example mentioned in class and I think it's similar to I'm asked to do. I think instead of returning something I need to print something. But the loop information in between, I need to change the code for it to match mine to give instructions on what to do. I got lost in my code and I don't know what to input for the code in bold python.
Example from class:
We’ve seen that entries in a dictionary can be accessed using keys. In the same way,
items in a list can be accessed by index, the numerical position of the item, counting
the first position as 0, the next as 1 and so on. If papers is the list [17, 0, 8, 3, ..., 14],
then papers[0] is 17, papers[1] is 0 and so on, up through papers[29] which is 14. In
this example, the key fact is that papers[3] is 3, showing that Student 3 got his or her
own paper.
Once papers has been shuffled, the following code does the checking we want:
[b]for student in range(classSize): if papers[student] == student: return 'warning' return 'okay'[/b]This checks if papers[0]—the paper given back to Student 0—is 0; then if papers[1]
is 1 and so on. If a match is found, the function paperStatus immediately
stops—without finishing the for statement—and returns the answer 'warning'. If the
for statement completes, it must be because no match was found. In this case,
paperStatus returns 'okay'.