0

What’s wrong with this code? Airline ticketing system

total = 0 i = 0 while i <= 5: x = input() age = int(x) if age < 3: continue else: total += 100 i += 1 print(total)

10th Feb 2021, 7:37 AM
Anna Karenina
4 Respostas
+ 8
Anna Karenina You have to add 100 when age is greater than 3. There is only 5 passenger so there should be i < 5 as i initialised with 0 total = 0 i = 0 while i < 5: x = input() age = int(x) if age > 3: total += 100 i += 1 print (total)
10th Feb 2021, 7:45 AM
A͢J
A͢J - avatar
0
I think there is something wrong with the IDE but im not shure im a beginner but: This is my try with the while Loop: total = 0 i =0 while i<5: age = int(input()) if age<3: continue else: total +=100 i +=1 print(total) I get an Error: Traceback (most recent call last): File "/usercode/file0.py", line 4, in <module> age = int(input()) EOFError: EOF when reading a line But with a For-Loop it works: total = 0 for i in range (5): age = int(input()) if age<3: continue else: total +=100 print(total)
9th Jun 2021, 1:40 AM
Adrian Mück
Adrian Mück - avatar
0
I also had the same EOFError like Adrian. My initial code was: total = 0 i = 0 while i < 5: age = int(input()) if age > 3: total += 100 else: continue i += 1 print(total) the suggested For-loop also works in my case. BUT this code works now: total = 0 i = 0 while i < 5: i += 1 age = int(input()) if age > 3: total += 100 else: continue print(total) Just putting the i += 1 infront of the input. I think that makes sense because, otherwise it will also skip that command if age < 3 and the while-loop does not count down.
18th Nov 2021, 3:59 PM
Francesco Walenszus
0
it is correct total = 0 i = 0 while i < 5: age = int(input()) if age > 3: total += 100 else: i += 1 continue i += 1 print(total)
25th Mar 2022, 8:28 PM
Leonid Davydiuk