0

Why isnt my break statement working help me figure out ....

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=="+": result=(num1+num2) print(result) elif operation=="-": print(num1-num2) elif operation=="stop": break print("stop") elif operation=="/": print(num1/num2) elif operation=="*": print(num1*num2)

18th Jul 2019, 10:32 PM
Umar Abbas
7 Respuestas
+ 3
Sololearn takes all input at one time in their non-web playgrounds, so it will loop until the user has no more input and an EOF occurs. Just put a break statement after the last elif statement like this: elif operation == “*”: print(num1 * num2) break
18th Jul 2019, 10:53 PM
Pete Cowling
Pete Cowling - avatar
+ 1
The break statement is working. But just works when u input "stop". U may need a break statement for each if or elif statement.
18th Jul 2019, 11:22 PM
Mauricio De Martino
Mauricio De Martino - avatar
+ 1
Umar Abbas if put stop at the first line, 2 at the second and 3 at the third, u will see. Be careful how SoloLearn use inputs, like Peter C... said. Read the input area of sololearn when u put run.
18th Jul 2019, 11:56 PM
Mauricio De Martino
Mauricio De Martino - avatar
+ 1
Why u need a break for each? Because u are Newbie. If u use a function, don't need. when u use an if st, for example, u may need to say what to do next. if "something"... break. elif "something "... break.
19th Jul 2019, 12:00 AM
Mauricio De Martino
Mauricio De Martino - avatar
0
Ive tried it that way also peter
18th Jul 2019, 10:55 PM
Umar Abbas
0
Mauricio i have tried puting "stop" but it always ends with an EOF error , why would i need a break st for each elif woulnt one be enough for the entire loop
18th Jul 2019, 11:53 PM
Umar Abbas
0
I do understand your point but im confused bcs the simple calulator in the solo lesson is not much different from my one that also with one break statement, reason i want to make clear is i want to learn from my mistakes ...
19th Jul 2019, 12:06 AM
Umar Abbas