anyone help me with this code problem | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

anyone help me with this code problem

you are making a ticket System the price of a singelt ticket is $100 dollar. for the ticcket under the of 3. the ticket is free. program need to take the age of 5 passenger as an input and output the total price for the ticket sample input 18 24 2 5 42 sample output 400 total = 0 x = 0 while x < 5: age = int(input()) if age >3: total += 100 x+1 print(total) This is my code the problem is it didn't calculate the input..

20th Nov 2023, 8:18 AM
Omel Oncepido
Omel Oncepido - avatar
11 Answers
+ 5
Where is your attempt? If you post your code we can help you.
20th Nov 2023, 8:23 AM
Keith
Keith - avatar
+ 4
Simanye There is no need for the else statement since it does nothing to change the variable. Also, posting ready made codes and answers is against forum guidelines. That's why I asked for their attempt 😉
20th Nov 2023, 9:11 AM
Keith
Keith - avatar
+ 3
Which course? Lesson name? Which language? Maybe you need to review the lessons. The code posted by another user in this discussion is one possible solution using Python.
20th Nov 2023, 9:20 AM
Keith
Keith - avatar
+ 2
pls Omel Oncepido post your code too cuz this place is nor for getting readymade solutions first try it yourself and than still you unable to make it well , than we will help you!
20th Nov 2023, 11:13 AM
Alhaaz
Alhaaz - avatar
+ 1
total_price=0 for i in range(5): age=int(input()) if age>3: total_price=total_price+100 else: total_price=total_price print(total_price)
20th Nov 2023, 9:02 AM
Simanye
Simanye - avatar
+ 1
i forget to indecate. it's firtime for posting here, pardon all
20th Nov 2023, 11:25 AM
Omel Oncepido
Omel Oncepido - avatar
+ 1
Hi ! You have to indent the if code block.
22nd Nov 2023, 7:02 AM
Ardent
+ 1
total = 0 x = 0 while x < 5: age = int(input()) if age > 3: total += 100 x += 1 print(total) here you go bro
22nd Nov 2023, 7:08 AM
AMINDU
AMINDU - avatar
0
I'm totally confused calculate the input from user
20th Nov 2023, 9:13 AM
Omel Oncepido
Omel Oncepido - avatar
0
ohhh, pardon for lack of my info. about the problem. this one is phytoon lang. program problem
20th Nov 2023, 9:33 AM
Omel Oncepido
Omel Oncepido - avatar
0
I think your code is not producing the output you're expecting due to incorrect indentation. Your if statement and the 2 lines below are not within the while loop. You need to shift them right so that the total gets updated for each input. (or maybe it's just displaying weirdly on my phone 😁)
20th Nov 2023, 11:25 PM
Si Carter
Si Carter - avatar