+ 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)
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
+ 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
...
+ 2
Oh thank you