+ 1
How to write a code that count the number of inputs and times it with a fixed number? Thank you!
Question: 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. My Answer: age = int(input()) while True: if age <= 3: continue if age > 3: print (100)
9 Answers
+ 1
ages = []
total = 0
i = 0
while i < 5:
x = int(input())
ages.append(x)
i += 1
for age in ages:
if age >= 3:
total += 100
print(total)
Note : you should write the five inputs in seperate line like this
20
24
23
26
2
+ 1
âtotal = 0
for _ in range(5):
x = int(input())
if x >= 3:
total += 100
print(total)â
For this code that you wrote, what does the _ represent? Is "range" a command word? How does this code repeat five times without using the while loop? Thank you!
+ 1
_ is not default u can use any character instead of it like i or num, ...etc but not any Python keywords
range() is a built in method and it's makes the code loop 5 times
I advise u to search đđ about range() method and you will understand the code
+ 1
Okkkk thank you very much!
0
I did this to manage me to loop on the five ages instead of using 5 variables ravilnicki
0
Nice đđ
ravilnicki