0
You are making a ticketing system. The price of a single ticket is $100. For children under 3 years of age, the ticket is fre
You are making a ticketing system. The price of a single ticket is $100. For children under 3 years of age, 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
9 Réponses
+ 4
For s help will be needed in addition:
- a tag with programming language,
- a programming question,
- to an attempt, which at the best is saved on Sololearns Playground, and prvided here a link to it.
+ 3
You should print total after completing loop so it only print once and the end result.
If you add p -= 1 inside if block, then it's executed only when age>2 is true but you need to update it every time after taking input.. So add it outside if block.
total = 0
p = 5
while p>0 :
age = int( input() )
if age > 2 :
total += 100 #inside if
p -= 1 #outside if
print(total) #after loop
+ 2
cost = 100
total_cost = 0
age = []
n = 5
for i in range(0,n):
age.append(int(input("enter age: ")))
for j in range(0,n):
if age[j] <= 3:
total_cost += 0
else:
total_cost += cost
print(total_cost)
+ 1
Your try?
+ 1
hint1: input() have to be in loop
hint2: only add 100 to total when age is greater than 2.
hint3: update p-=1 outside if.
why : read the task carefully again..
+ 1
I'm so frustrated right now...
I get an EOFerror on the fifth line when I run this
total = 0
p = 5
while p > 0:
age = int(input())
if age >2:
total += 100
print(total)
p -=1
+ 1
Jayakrishna🇮🇳 like this?
0
Its python... My trial went thus;
total = 0
p = 5
age = int(input())
while p > 0:
total += 100
if age >2:
continue
print(total)
p -=1
0
Jayakrishna🇮🇳 I got it... Here's the correct program
total = 0
x = 0
while x < 5:
age =int(input())
if age > 3:
total += 100
x += 1
print(total)
Thanks