When I tried making Calculator in python it says "break" Outside loop | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
0

When I tried making Calculator in python it says "break" Outside loop

Please Ans this.......It says Syntax Error....'break' outside loop

13th Feb 2019, 12:26 PM
Rohan Kiratsata
Rohan Kiratsata - avatar
18 Answers
+ 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... :(
14th Feb 2019, 12:08 PM
HonFu
HonFu - avatar
+ 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!
13th Feb 2019, 12:30 PM
HonFu
HonFu - avatar
+ 1
Hm, I just tried it, typed quit as input, code ended.
13th Feb 2019, 12:48 PM
HonFu
HonFu - avatar
+ 1
I mean, I ran your code and didn't get the error message - break worked just fine!
13th Feb 2019, 1:11 PM
HonFu
HonFu - avatar
+ 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.)
13th Feb 2019, 1:26 PM
HonFu
HonFu - avatar
+ 1
Ya right ✔
13th Feb 2019, 2:04 PM
Rohan Kiratsata
Rohan Kiratsata - avatar
+ 1
It is working...but i am getting new error.....elif uin=="add": At invalid syntax
14th Feb 2019, 11:03 AM
Rohan Kiratsata
Rohan Kiratsata - avatar
+ 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?
14th Feb 2019, 11:06 AM
HonFu
HonFu - avatar
+ 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. ;-)
14th Feb 2019, 11:25 AM
HonFu
HonFu - avatar
+ 1
I left too many space...so i was getting error
14th Feb 2019, 11:33 AM
Rohan Kiratsata
Rohan Kiratsata - avatar
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")
13th Feb 2019, 12:40 PM
Rohan Kiratsata
Rohan Kiratsata - avatar
0
I din't Get You
13th Feb 2019, 1:00 PM
Rohan Kiratsata
Rohan Kiratsata - avatar
0
Ok Thanks... I will try it again
13th Feb 2019, 1:18 PM
Rohan Kiratsata
Rohan Kiratsata - avatar
0
Its done
14th Feb 2019, 11:21 AM
Rohan Kiratsata
Rohan Kiratsata - avatar
0
Thank you very much
14th Feb 2019, 11:22 AM
Rohan Kiratsata
Rohan Kiratsata - avatar
0
I going to put My simple Calculator program in Code Playground...
14th Feb 2019, 11:22 AM
Rohan Kiratsata
Rohan Kiratsata - avatar
0
Ya...
14th Feb 2019, 11:32 AM
Rohan Kiratsata
Rohan Kiratsata - avatar
0
I have posted my code https://code.sololearn.com/cpsL3bcoFrZz/?ref=app Please tell my Mistakes...still i am getting error
14th Feb 2019, 11:49 AM
Rohan Kiratsata
Rohan Kiratsata - avatar