Ticketing System Practice in Python | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Ticketing System Practice in Python

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 #my code goes from here: ages=input() i=0 while True: for age in ages: if ages >=3: i+=1 else: continue print (i*100) I'm getting error like " if ages >=3: TypeError: '>=' not supported between instances of 'str' and 'int'". Can anyone help here? Thank you!

20th Apr 2021, 1:32 PM
Na T
1 Answer
0
You need to take 5 inputs. You need to cast input to int to do calculations or comparisons. "while True:" starts an endless loop that you have to stop eventually with "break". When you iterate through an array (for loop) you should also use the iteration variable, "age" in your case. You don't need "else: continue"
20th Apr 2021, 2:31 PM
Benjamin Jürgens
Benjamin Jürgens - avatar