Ask coding questions

← Back to all posts
calculator
LorraineDavidso (1)

Hi I am stuck at near the end of build a calculator, number 38 break 39 is blanck and 41 print("please enter a valid input!!")
number 38 says when i press enter syntax error break outside loop
i am new to all this can someone help please.

Commentshotnewtop
LorraineDavidso (1)

Thank you guys for the help but i think I am just going to give up it will be less marks for my college work i can not sort this.

Codejira (165)

The break statement is allowed only inside for and while loops.

With your indentation the code from line 17 on belongs to the function div(), but the while loop contains only one line.

I believe print("Welcome") is the first line to be executed. Give it no indentation then. Ditto while True:

Following lines need at least one level of indentation in order to belong to the while loop.

Oh, and please use 4 spaces to indent, so it looks something like this:

print("welcome!!")
while True:
    user_input=raw_input("enter calculator type:")

    if user_input=='+':
        print("to calculate(number1+number2):")
        add(int(input("enter number1:")),int(input("enternumber2:")))

You can detect faulty indentation so much better then.

CodeLongAndPros (1362)

You need to indent lines 21 to 38 by one. Select them with your mouse or Shift, and press C-[

LorraineDavidso (1)

@CodeLongAndPros Hi Thank you very much for your help but i think i am just going to give up with this all the less marks for my college work.

CodeLongAndPros (1362)

@LorraineDavidso

just going to give up with this all the less marks for my college work.

Uhhhhh...

Sure?