can anyone please tell me what is the mistake? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 4

can anyone please tell me what is the mistake?

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

17th Aug 2019, 5:57 PM
Unknown
6 Answers
+ 3
The code works when line 15 and 16 is indented. You can also inline a break statement to stop the program from looping. 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": num1 = float(input("Enter a number: ")) num2 = float(input("Enter another number: ")) result = str(num1 + num2) print("The answer is " + result) break
17th Aug 2019, 6:57 PM
vcx
+ 3
The while loop is used to do more than one calculation. so you can say "add" and then 5 and the other value 7, so result will show 12. And it will immediately be ready for a new calculation. If input is "quit" the program will be terminated.
17th Aug 2019, 7:24 PM
Lothar
Lothar - avatar
+ 2
VCX king! it worked very well!
17th Aug 2019, 7:21 PM
Unknown
+ 1
i am not entirely sure why, but your problem seems to be in the break or perhaps the while why are you using a while true?
17th Aug 2019, 6:35 PM
Brave Tea
Brave Tea - avatar
+ 1
Elie Aro 😊 Thanks bud 👊
17th Aug 2019, 7:23 PM
vcx
0
Cbr✔[ Most active ] thanks! I noticed that, but don’t know why. can you maybe explain why one would use a while statement here? also do you know why it doesn’t work? just for my own edification :)
17th Aug 2019, 6:40 PM
Brave Tea
Brave Tea - avatar