+ 1

It works on PyCharm but not on SoloLearn Playground. Why is that?

while True: print("Options:") print("Enter 'add' to add two numbers") print("Enter 'subtract' to subtract two numbers") print("Enter 'multiply' to multiply two numbers") print("Enter 'divide' to divide two numbers") print("Enter 'quit' to end the program") user_input = input(": ") if user_input == "quit": break elif user_input == "add": a = float(input("enter first no.=")) b = float(input("enter second no.=")) print(a+b) elif user_input == "subtract": a = float(input("enter first no.=")) b = float(input("enter second no.=")) print(a-b) elif user_input == "multiply": a = float(input("enter first no.=")) b = float(input("enter second no.=")) print(a*b) elif user_input == "divide": a = float(input("enter first no.=")) b = float(input("enter second no.=")) print(a/b) else: print("Unknown input")

7th Jun 2020, 11:21 AM
Winston Churchill
Winston Churchill - avatar
2 Réponses
+ 3
Code playground isn't interactive you need to enter all the inputs at once here add 3 4 subtract 5 2 quit
7th Jun 2020, 11:25 AM
Abhay
Abhay - avatar
+ 1
If the user doesn't input quit... The first while loop in the 1st line never ends..... And thus.... When you do a sum..... PyCharm again starts from the 1st..... But sololearn has a loophole.... It takes inputs only once at the beginning... So if you don't end the input without a "quit" in sololearn, the code will not be executed
7th Jun 2020, 11:26 AM
The Kanks
The Kanks - avatar