+ 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.

7th Nov 2022, 7:04 PM
Engineer X
Engineer X - avatar
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..
7th Nov 2022, 7:28 PM
Jayakrishna šŸ‡®šŸ‡³
+ 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"
7th Nov 2022, 7:16 PM
Jayakrishna šŸ‡®šŸ‡³
+ 2
Thanks
7th Nov 2022, 7:53 PM
Engineer X
Engineer X - avatar
+ 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.
7th Nov 2022, 7:18 PM
Engineer X
Engineer X - avatar
+ 1
Though I am pretty sure my code is correct
7th Nov 2022, 7:19 PM
Engineer X
Engineer X - avatar
+ 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.
7th Nov 2022, 7:20 PM
Engineer X
Engineer X - avatar
+ 1
But what can I type to read the all those words at once and calculate the total price?
7th Nov 2022, 7:24 PM
Engineer X
Engineer X - avatar
+ 1
Using while loop was the only thing I could find.
7th Nov 2022, 7:24 PM
Engineer X
Engineer X - avatar
+ 1
And even the program itself says that it did entered 3 times. Which means we need a loop.
7th Nov 2022, 7:25 PM
Engineer X
Engineer X - avatar
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..
7th Nov 2022, 7:22 PM
Jayakrishna šŸ‡®šŸ‡³