+ 4

Ballpark Orders

Can anyone help me in fixing the error in this code? str=input() ord=str.split(' ') price=0 for i in range(4): if ord[i]=='Nachos': price+=6.00+0.07*6.00 elif ord[i]=='Pizza': price+=6.00+0.07*6.00 elif ord[i]=='Cheezeburger': price+=10.00+0.07*10.00 elif ord[i]=='Water': price+=4.00+0.07*4.00 elif ord[i]=='Coke': price+=5.00+0.07*5.00 else: price+=5.00+0.07*5.00 print(price)

3rd Jul 2024, 12:57 PM
Jaya Vishwakarma
Jaya Vishwakarma - avatar
3 odpowiedzi
+ 4
Hello Jaya I think only error in the code is simple typo You have written "Chee'z'eburger" instead of Cheeseburger Hope it helps you ☺️✨ *Other suggestions:- You can take input and split them in a single line ord = input().split() By default it splits by space Instead of multiplying by 0.07 again and again you can multiply by 1.07 at the last
3rd Jul 2024, 1:34 PM
Hacker Badshah
Hacker Badshah - avatar
+ 6
Jaya Vishwakarma , just a remark from my side: > instead of using a range(...) to generate indexes and use them to access the various items in the order, we can iterate directly over the *ord* list: ... for order in ord: if order =='Nachos': price+=6.00+0.07*6.00 elif order =='Pizza': price+=6.00+0.07*6.00 ...
4th Jul 2024, 6:46 PM
Lothar
Lothar - avatar
+ 2
Oh thank you
4th Jul 2024, 2:41 AM
Jaya Vishwakarma
Jaya Vishwakarma - avatar