+ 1
26.3 Ticket Prices Python
Hello, I’m having trouble with this code. I keep getting an error about age = input(), unless I put break where continue is. If I put break there, two of the tests are satisfied, but it breaks whenever someone younger than 3 is buying a ticket. total = 0 #your code goes here while True: age = input() if int(age) >= 3: total +=100 if int(age) < 3: total +=0 continue print(total)
17 ответов
+ 8
It turns out when the file ended, there was no input resulting in an error in the loop (end of file error or EOFError). To fix this you can use try and except or you can set a limit on the loop. See below if you want the code.
Turns out there are a couple ways to do this:
1) If you want as many passengers as want to get on board:
total = 0
#your code goes here
while True:
try:
age = input()
except EOFError:
break
if int(age) >= 3:
total +=100
if int(age) < 3:
total +=0
continue
print(total)
2) You only want to allow 5 passengers
total = 0
p = 1
#your code goes here
while p <= 5:
age = input()
if int(age) >= 3:
total +=100
p +=1
if int(age) < 3:
total +=0
p +=1
continue
print(total)
+ 6
total = 0
people = 0
while people < 5:
age = int(input())
if age > 3:
total +=100
people += 1
else:
people +=1
print(total)
just wanted to help, and it works
+ 3
My code looks like that:
total = 0
i = 0
while i < 5:
age = int(input())
i += 1
if age > 3:
total += 100
print(total)
I only check when age is bigger than 3 because .. it’s clear that everything else will be smaller than 3. I don’t have to add zeros.
+ 2
My code was throwing eof errors saying it was the input line, but the actual problem was that I accidentally set the number of iterations from 0-5 which Is one more than the program entered. When I changed p to 1 instead of zero or 5 to 4 that changed my iterations to 5 and it worked.
+ 2
total = 0
i = 0
while i < 5 :
age = int(input())
if age > 3 :
total = total + 100
i += 1
print(total)
+ 1
Hi! Hint: in the age variable, you use input and it is saved as a string. and you need to save it as a number...
+ 1
Here is the way I found:
total = 0
#your code goes here
count = 0
while count <= 4:
age = input()
if int(age) >= 3:
total += 100
count += 1
else:
count += 1
continue
print (total)
+ 1
I wrote this code and it is working.
total = 0
#your code goes here
i=1
while i<6:
age=int(input())
if age<3:
i+=1
continue
else:
total+=1
i+=1
price=int(total)*100
print(price)
+ 1
Age=int(input())
Total=0
While(age>=0):
If(age<=3):
Total+=0
Elif(age>3):
Total+=100
Print (total)
break
+ 1
it's the shortest ☺️
total = 0
i=1
while i<=5 :
age=int(input())
i+=1
if age<3:
continue
total+=100
print(total)
+ 1
I have tried several ways including many described here to no success. This is my code today:
total = 0
#your code goes here
passengers = 1
while passengers <= 5:
try:
age = input()
except EOFError:
if int(age) >= 3:
total += 100
passengers += 1
if int(age) < 3:
total += 0
passengers += 1
continue
print(total)
None of the test cases passes. Any pointers?
+ 1
I have the same issue:
price = 100
total = 0
for i in range(5):
age = int(input())
if age > 3:
total += price
elif age <= 3:
continue
print(total)
Can someone point out where the error is???
+ 1
why do we have to type age=int(input()) after while syntax?
+ 1
and why do we have to limit the number of passengers to 4 if there can be 5 of them?
+ 1
Please where is the correct answer am also having problem with that one
0
Mine is shorter but works:
total = 0
p = 0
while p < 5:
x = int(input())
if x > 3:
total += 100
p += 1
else:
total += 0
p += 1
print(total)
0
passenger=0
sum=0
while passenger<5:
passenger+=1
age=int(input())
if age>3:
sum+=1
else:
continue
print(sum*100)
#thats works successfully