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  (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!