Cant get the loop to break | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

Cant get the loop to break

while True: operation=input("choose an operation from +,-,/,*: ") print(operation) num1=float(input("enter a value: ")) print(num1) num2= float(input("enter another value: ")) print(num2) if operation=="stop": print("stopping") break elif operation=="+": result=(num1+num2) print(result) elif operation=="-": print(num1-num2) elif operation=="/": print(num1/num2) elif operation=="*": print(num1*num2)

11th Jul 2019, 10:51 PM
Umar Abbas
4 Answers
0
you can use the “break” keyword somewhere in that code when needed to break the loop
11th Jul 2019, 11:55 PM
Pikachu
Pikachu - avatar
0
Ive done that if you ve seen my code pikachu.....
12th Jul 2019, 5:01 AM
Umar Abbas
0
i see but operation may never equal “stop” if that happens, the code will never break.
12th Jul 2019, 1:51 PM
Pikachu
Pikachu - avatar
0
I have given the program a 'stop' input , i dont understand why its not breaking as operation is equal to stop
12th Jul 2019, 2:59 PM
Umar Abbas