+ 1

I want to know how I can count multiple times s input in this code to work

https://code.sololearn.com/ceGOjNyWZra1/?ref=app

26th May 2022, 1:39 AM
Alejandro47
Alejandro47 - avatar
6 odpowiedzi
+ 1
Use a while loop like While True: So that it can easily enter the loop and then ask for the input there......so it will keep asking input for stopping this you can also include a condition like if user input y it will again ask for input otherwise exit the loop and finish the program ✌️ Ex: while True: y = input() """......... enter your Logic........""" abc = input() if abc ="y": continue else: break Use this code: total = 0 while True: y = input() if y in "Nachos": total += 6.00 if y in "Pizza": total += 6.00 if y in "Cheeseburger meal": total += 10.00 if y in "Water": total += 4.00 if y in "Coke": total += 5.00 else: print("Not in data") tax = total*0.07 print(total+tax) ab = input("Want tk use again(type y for yes or n for no)?") if ab == "y": continue elif ab == "n": break else: print("Invalid Input") break
26th May 2022, 6:16 AM
Avi
Avi - avatar
+ 2
Which language is it? Pls change the question tags to the language. Also, pls save the code in Code Playground, as public, then edit the question, using "+" button to link the code. Makes it way easier for us to exchange and test ideas. You can reverse the logic: loop through the words in input, then count occurrences of the specific ones. Multiple word patterns, like "Cheeseburger meal", will require additional logic, but good coding also requires solving one problem at a time.
26th May 2022, 2:19 AM
Emerson Prado
Emerson Prado - avatar
+ 2
Alejandro47 You will need to use a while loop to continue prompting input until an exit condition is met. y = input() while y != 'exit': if pizz... etc etc y = input() The snippet shows that the while loop will test your input, then will prompt again for another input which it will test. when y == "exit", the loop will terminate
26th May 2022, 3:09 AM
Rik Wittkopp
Rik Wittkopp - avatar
+ 2
Avi , though your answer helps solving the problem, it defeats learning, which is the idea of SoloLearn. Pls always prefer giving hints for the OP to find the solution, instead of giving finished code.
26th May 2022, 9:12 AM
Emerson Prado
Emerson Prado - avatar
+ 2
Emerson Prado ok will take care next time......
26th May 2022, 9:18 AM
Avi
Avi - avatar
26th May 2022, 9:20 AM
Rik Wittkopp
Rik Wittkopp - avatar