+ 2
Need Help
I want to type a code that users info 4 times and shows the total price. x = 0 i = 0 while i < 4 : n = input() i += 1 if n == "Nachos" or "Pizza" : x += 6.00 elif n == "Cheseburger" : x += 10 elif n == "Water" : x += 4.00 elif n == "Coke" : x += 5.00 else : x += 5.00 x = (x * 7) / 100 print(x) I typed this code but it doesn't work (shows an error). Any answer will be appreciated.
10 Answers
+ 3
n = input() #reads entire line
n.split() # splits by space into words of list
So simply
words = input().split()
x = 0
#By for loop :
for n in words:
# do next calculations from here..
+ 2
What is the error you getting?
Between n=="Nachos" or "pizza" Is always true. You need to separate like :
n=="Nachos" or n== "pizza"
+ 2
Thanks
+ 1
No I am actually working on a " couch pro project " and when I run the code it says " line 4 n = input() " can not read it.
+ 1
Though I am pretty sure my code is correct
+ 1
The thing is they also respond:
Your code takes the user Input 4 times while the user entered entered 3 times and your code stopped working.
+ 1
But what can I type to read the all those words at once and calculate the total price?
+ 1
Using while loop was the only thing I could find.
+ 1
And even the program itself says that it did entered 3 times.
Which means we need a loop.
0
In code coach, there no need loop for input().
Input() reads entire line as string. And your task has single line of input of 4 words separated by space. So read once and split into words.. Then by a loop, check values for total.
Hope it helps..