Python Forum
Computer science can you help me with the last part of the code after mentionedWords.
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Computer science can you help me with the last part of the code after mentionedWords.
#9
@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:
[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'.
Reply


Messages In This Thread
RE: Computer science can you help me with the last part of the code after mentionedWords. - by shirleylam852 - Nov-28-2020, 01:10 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Having trouble with my Computer Science task Dunxx 1 1,869 Oct-07-2021, 12:32 PM
Last Post: DeaD_EyE
  computer science coursework, read the text please and tell me if theres any specifics sixcray 4 2,756 Nov-11-2020, 03:17 PM
Last Post: buran

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020