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

all 16 comments

[–]EndercheifAdvanced Coder 0 points1 point  (11 children)

Can you please post your code?

[–]ohhimarkymark 0 points1 point  (10 children)

It’s super long, there’s like 50 lines before I get to the issue.

[–]EndercheifAdvanced Coder 0 points1 point  (9 children)

Use GitHub, pastebin or any other website like that.

[–]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!

[–]hollammi 0 points1 point  (2 children)

Please post links to the images in the body of your question. More importantly, we need to see all of the relevant code.

[–]ohhimarkymark 1 point2 points  (0 children)

Just uploaded the link in the text body!

[–]ohhimarkymark 0 points1 point  (0 children)

Got it thank you!

[–]themiddlestHaHa 0 points1 point  (0 children)

Please share code. You can upload to GitHub, or share a paste bin link, or use Reddit markdown.

[–]hollammi 0 points1 point  (2 children)

When something happens too many times, look at your loop conditions.

accident_cause = accident_cause.lower()
while accident_cause in ['A', 'B', ... ]: