0
When I tried making Calculator in python it says "break" Outside loop
Please Ans this.......It says Syntax Error....'break' outside loop
18 Antworten
+ 3
Does your whole code belong to the while True?
Then you have to indent all of it.
That's not the only problem, but SoloLearn is being annoying again right now, can't run any code... :(
+ 2
It means that you used break outside of a loop which makes no sense.
Please show us your code so we can tell you more!
+ 1
Hm, I just tried it, typed quit as input, code ended.
+ 1
I mean, I ran your code and didn't get the error message - break worked just fine!
+ 1
Normally, if there is that mistake, you probably have made an indentation error.
It should look like this:
for whatever:
....
break
but does look like this instead:
for whatever:
....
break
Maybe you mixed up spaces and tabs somehow? (Just guessing here.)
+ 1
Ya right ✔
+ 1
It is working...but i am getting new error.....elif uin=="add":
At invalid syntax
+ 1
You should put your code into Code Playground so that we can see what it *really* looks like.
Because again what you say shouldn't be the case, the line looks correct.
Have you looked at the line before? Closing parenthesis missing?
+ 1
Very good. That may make it easier for us to see where's the problem.
Was it in the line before?
Remember: Python doesn't show you where the error is, it shows you where it *recognized* it!
So whenever you're confident everything is alright with the line, look in the line before. Very often it's these brackets - so easy to forget one. ;-)
+ 1
I left too many space...so i was getting error
0
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 #its gives error here
elif user_input == "add":
...
elif user_input == "subtract":
...
elif user_input == "multiply":
...
elif user_input == "divide":
...
else:
print("Unknown input")
0
I din't Get You
0
Ok Thanks... I will try it again
0
Its done
0
Thank you very much
0
I going to put My simple Calculator program in Code Playground...
0
Ya...
0
I have posted my code
https://code.sololearn.com/cpsL3bcoFrZz/?ref=app
Please tell my Mistakes...still i am getting error