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)
7 Réponses
+ 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
+ 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.
+ 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.
+ 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.
0
Ive tried it that way also peter
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
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 ...