0

[ANSWERED] Having trouble with "break and continue" task.

So the task is to take the age of 5 passengers boarding a plane. If a passenger is below the age of 3 then their ticket is free. Anyone older than that will be $100. After inputting the ages 5 time it will then print out how much the bill will be. I am getting an error on line 6. Here is the error and code. Any help? Error: Traceback (most recent call last): File "/usercode/file0.py", line 6, in <module> age = input() EOFError: EOF when reading a line Code: total = 0 #Total amount of money they will pay passengers = 5 #Amount of passengers that will be boarding while passengers >= 0: age = input() if int(age) >= 3: total += 100 else: continue passengers -= 1 print(total)

18th Oct 2021, 8:06 PM
WebFreak
WebFreak - avatar
5 odpowiedzi
0
Remove the else clause. 1. The way you implemented things you don't need it. 2. The continue statement prevents the last line in the loop from executing. Because of this passengers doesn't count down correctly.
18th Oct 2021, 8:23 PM
Simon Sauter
Simon Sauter - avatar
+ 2
Hunter MacInnes passengers should be greater than 5 so change while passengers > 0: And first decrement passengers by 1 then check condition and use continue. passengers -= 1 if int(age) >= 3: total += 100 else: continue
18th Oct 2021, 8:22 PM
A͢J
A͢J - avatar
0
Your while loop has six iterations (for passengers values 5, 4, 3, 2, 1, 0). But sololearn only gives five inputs. So the program keeps looking for the sixth input, which never comes. Change the while condition from >= 0 to > 0 and it should work.
18th Oct 2021, 8:14 PM
Simon Sauter
Simon Sauter - avatar
0
Changing >=0 to >0 still gives me the same error.
18th Oct 2021, 8:17 PM
WebFreak
WebFreak - avatar
0
Here you are: total = 0 #Total amount of money they will pay passengers = 5 #Amount of passengers that will be boarding while passengers > 0: passengers -= 1 age = input() if int(age) >= 3: total += 100 else: continue print(total)
10th Mar 2024, 10:44 AM
David de Diego
David de Diego - avatar