+ 5

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)

16th Mar 2021, 3:27 AM
Navraj Singh
Navraj Singh - avatar
28 Respostas
+ 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))
16th Mar 2021, 7:35 AM
visph
visph - avatar
+ 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.
16th Mar 2021, 3:49 AM
Abir Hasan
Abir Hasan - avatar
+ 15
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)
26th May 2021, 5:33 PM
Virendra Agarkar
Virendra Agarkar - avatar
+ 11
total = 0 i = 1 while i <= 5: age = int(input()) if age >= 3: total += 100 else: total += 0 i += 1 print(total)
12th Sep 2021, 1:13 AM
C'loni Bailey
+ 3
total = 0 passenger = 0 while passenger < 5: age=int(input()) passenger +=1 if age <= 3: continue elif age > 3: total += 100 print(total)
12th Jan 2022, 3:22 PM
Damir Prlja
Damir Prlja - avatar
+ 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)
18th Feb 2022, 9:56 AM
Younes Benhaga
+ 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
13th Jan 2022, 11:32 AM
Shioke
+ 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)
24th Aug 2022, 11:18 AM
shwetal pawar
+ 1
total = 0 ticket = 100 passenger = 1 while passenger <=5: age = int(input()) if age >= 3: total += ticket passenger += 1 print (total)
1st Sep 2022, 10:14 AM
Pavel Sagirov
Pavel Sagirov - avatar
+ 1
total = 0 passengers = 0 ticket = 100 while passengers < 5: age=int(input()) passengers += 1 if age <=3: continue else : total += ticket print (total)
17th May 2023, 5:37 PM
André Elias Da Silva
André Elias Da Silva - avatar
+ 1
THIS IS CORRECT 🤙👌✌👍💯💯💯 #include <stdio.h> int main() { // Declare a variable to store the number of tickets ordered int tickets; if (scanf("%d", &tickets) != 1) { printf("Invalid input. Please enter a valid integer.\n"); } if (tickets < 0) { printf("Number of tickets cannot be negative.\n"); } float price = 7.45; float total = tickets * price; printf("Total: %.6f\n", total); return 0; }
12th Oct 2024, 12:47 PM
BAMIGBAYE IBUKUNOLUWAPO
BAMIGBAYE IBUKUNOLUWAPO - avatar
0
you only read the first age, since you only used int(input()) once
16th Mar 2021, 5:27 AM
John Doe
0
for i in range(5): age = int(input()) if (age >= 3): total += 100 print(total)
10th Sep 2021, 7:01 PM
guenaizi abdelkader
guenaizi abdelkader - avatar
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)
4th Jan 2022, 8:04 AM
Chief Satyam
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)
10th Feb 2022, 9:04 AM
Yuvraj Chouhan
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)
15th Feb 2022, 11:02 PM
Alcino Castelo
0
fees = 0 for i in range(5): if int(input())>=3: fees += 100 print(fees)
9th Mar 2022, 5:38 AM
Movie Download
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
22nd Mar 2022, 7:07 AM
Solomon Ayalew
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)
29th Mar 2022, 12:40 PM
Althaff Munawwars22000506-121647628
0
total = 0 i = 1 while i <= 5: age = int(input()) if age >= 3: total += 100 else: total += 0 i += 1 print(total)
30th Mar 2022, 9:04 AM
Ahmed Salouh Abdelmoried