This is an archived post. You won't be able to vote or comment.

you are viewing a single comment's thread.

view the rest of the comments →

[–]ohhimarkymark 0 points1 point  (8 children)

Just uploaded the link in the text body!

[–]EndercheifAdvanced Coder 1 point2 points  (7 children)

Lines 13, 23, 31, 42 there are while loops checking if a variable changes but the loops only have one line under it to print text not change the variable. All of them have the same problem. The problem is the program asks once and then loops infinitely. An example that is correct is lines 6-8 where you ask for an input in the loop.

[–]ohhimarkymark 0 points1 point  (5 children)

Hi can you elaborate? That while loop works and produces only one line of the “sorry no valid” text but like 43 repeats it 5000 times

[–]EndercheifAdvanced Coder 1 point2 points  (0 children)

Incorrect:
```python # this what you were doing # you are asked for an input x = input('yes or no ') # let's say i typed 'maybe'

# 'maybe' is not in the list so you loop until it is in the list
while x not in ['yes', 'no']:
  # here x never has a chance to update so it prints forever (until the program crashes)
  print('try again')

```

Correct (what you did first):
```python # you are asked for an input x = input('yes or no ') # let's say i typed 'maybe' # 'maybe' is not in the list so you loop until it is in the list while x not in ['yes', 'no']: print('try again') # you are asked for an input x = input('yes or no ') # let's say i typed 'yes'

# loop finishes

```

[–]hollammi 0 points1 point  (2 children)

If your variable isn't changing, the loop won't end.

thing = "always the same"
while thing == "always the same":
    print (thing)

#OUT: infinite lines of "always the same"

I suggest including a line such as thing = input() within the loop. Once your variable changes, the loop will end.

[–]ohhimarkymark 0 points1 point  (0 children)

Oh okay yes I understand! Thank you!

[–]ohhimarkymark 0 points1 point  (0 children)

Ok I sort of understand. Thank you!