+ 4
Can anyone tell me. How to solve this question.
You are making a ticketing system. The price of a single ticket is $100. For children under 3 years old, the ticket is free. Your program needs to take the ages of 5 passengers as input and output the total price for their tickets. Sample Input 18 24 2 5 42 Sample Output 400 Here is my try: 👇👇👇👇👇 age = int(input()) ticket = 100 total = 0 passengers = 1 while passengers <= 5: if age < 3: continue else: total += ticket passengers += 1 print(total)
27 Antworten
+ 30
"""
you must move 'input' inside the loop, and increment 'passengers' counter at each iteration for your while loop working as expected (actually, expect 5 greater or equal to 3 years passengers, skipping less than 3 years withput counting them)...
"""
# age = int(input())
ticket = 100
total = 0
passengers = 1
while passengers <= 5:
age = int(input()) # in the loop
passengers += 1 # always increment
if age < 3:
continue
else:
total += ticket
# passengers += 1
print(total)
"""
anyway, you could shorter your code by using for loop and range, and only testing for age >= 3:
total = 0
for i in range(5)
age = int(input())
if (age >= 3):
total += 100
print(total)
"""
or onelined:
"""
print(100*len(1for i in range(5) if int(input()) >= 3))
+ 26
Try this:
ticket = 100
total = 0
for i in range(5):
age = int(input())
if age < 3:
continue
else:
total += ticket
print(total)
You can use while loop like you did but for loop is simpler in this case.
+ 14
Answer of this problem is as follows:
total = 0
passenger = 0
while passenger < 5:
age=int(input())
passenger +=1
if age <= 3:
continue
elif age>3:
ticket = 100
total += ticket
print(total)
+ 11
total = 0
i = 1
while i <= 5:
age = int(input())
if age >= 3:
total += 100
else:
total += 0
i += 1
print(total)
+ 3
total = 0
passenger = 0
while passenger < 5:
age=int(input())
passenger +=1
if age <= 3:
continue
elif age > 3:
total += 100
print(total)
+ 3
a = int(input())
b = int(input())
c = int(input())
d = int(input())
e = int(input())
total = 0
if (a > 3):
total += 100
if (c > 3):
total += 100
if (d > 3):
total += 100
if (e > 3):
total += 100
if (b > 3):
total += 100
print (total)
+ 1
total = 0
ticket = 100
passenger = 0
while passenger < 5:
age = int(input())
passenger += 1
if age < 3:
continue
total = total + ticket
print(total)
#the key is to try and right the code for all 5 passengers first then add the 'continue' afterwards to eliminate for the code to ignore less than 3 year olds
+ 1
Try this-
total = 0
passenger = 0
#your code goes here
while passenger < 5:
age = int(input())
passenger+=1
if age <=3:
continue
elif age>3:
total +=100
print(total)
+ 1
total = 0
ticket = 100
passenger = 1
while passenger <=5:
age = int(input())
if age >= 3:
total += ticket
passenger += 1
print (total)
+ 1
total = 0
passengers = 0
ticket = 100
while passengers < 5:
age=int(input())
passengers += 1
if age <=3:
continue
else :
total += ticket
print (total)
0
you only read the first age, since you only used int(input()) once
0
for i in range(5):
age = int(input())
if (age >= 3):
total += 100
print(total)
0
total = 0
passenger = 0
ticket = 100
while passenger < 5:
age = int(input("Enter Age: "))
passenger += 1
#print(passenger)
if age < 3 :
continue
else:
total += ticket
print(total)
'''''''''''''''''''''
The second method that uses list and range:
#TICKETING SYSTEM
Ticket=100
l=[]
count=0
for i in range(5):
x=int(input("Enter Age of Passenger: "))
l.append(x)
for i in l:
if i<3:
continue
else:
count=count+Ticket
print("The Total Ticket is:",count)
0
total = 0
pas = 0
ticket=100
while pas<5:
age=int(input())
pas +=1
if age<3:
continue
else:
total=total+ticket
print(total)
0
total = 0
#your code goes here
i=0
while i <5:
idade = input()
age=int(idade)
i+=1
if age < 3 :
continue
else:
total+=100
print(total)
0
fees = 0
for i in range(5):
if int(input())>=3:
fees += 100
print(fees)
0
total = 0
passenger = 0
while passenger < 5:
age=int(input())
passenger +=1
if age <= 3:
continue
elif age>3:
ticket = 100
total += ticket
print(total)
coorect one
0
total = 0
passenger = 0
while passenger < 5:
age=int(input())
passenger +=1
if age <= 3:
continue
elif age>3:
ticket = 100
total += ticket
print(total)
0
total = 0
i = 1
while i <= 5:
age = int(input())
if age >= 3:
total += 100
else:
total += 0
i += 1
print(total)
0
total=0
ticket=0
limit=5
while total<limit:
age=int(input())
if age<3:
ticket!=0
elif age>3:
ticket+=100
total+=1
print(ticket)