+ 1

Unindent does not match any outer indentation level?

Hey developers I am a beginner in python and I'm facing this error in my code for creating the basic calculator. Code: while True: print('Options:') print('Enter add to add two numbers') print('Enter minus to subtract two numbers') print('Enter multiply to multiply two numbers') print('Enter divide to divide two numbers') print('Enter quit to exit the calculator') user_input = input(":") if user_input == "quit": break elif user_input == 'add': num1 = float(input('Enter a number')) num2 = float(input('Enter another number')) result = str(num1 + num2) print('THE ANSWER IS' + result) elif user_input == 'minus': num1 = float(input('Enter a number')) num2 = float(input('Enter another number')) result = str(num1 - num2) print('THE ANSWER IS' + result) elif user_input == 'multiply': num1 = float(input('Enter a number')) num2 = float(input('Enter another number')) result = str(num1 * num2) print('THE ANSWER IS' + result) elif user_input == 'divide': num1 = float(input('Enter a number')) num2 = float(input('Enter another number')) result = str(num1 / num2) print('THE ANSWER IS' + result) else: print("ERROR 404") print("Thank you for using eCalc") what does this mean? Thanks, if you answered

23rd Mar 2020, 2:00 PM
Mubashir M
Mubashir M - avatar
11 ответов
+ 2
If u need the program let the user to continuously enter the 3 values , u should use (while except )expression but it is not work at this App
23rd Mar 2020, 2:29 PM
Muhammad Galhoum
Muhammad Galhoum - avatar
+ 1
Mubashir M I believe what you need is 'revision' go through python course of Sololearn again and this will help too: https://code.sololearn.com/cT5BRIbkia21/?ref=app
23rd Mar 2020, 2:16 PM
Daljeet Singh
Daljeet Singh - avatar
+ 1
Show this code will do what u need num1=float(input("plz enter the first number : ")) num2=float(input("plz enter the second number : ")) sign=input("plz enter your sign : ") if sign =="+": sum=num1+num2 print("the sum is {}".format(sum)) elif sign=="-": sub=num1-num2 print("the sub is {}".format(sub)) elif sign=="*": mul=num1*num2 print(" the multiplication is {}".format(mul)) elif sign=="/": if num2 ==0: print("can't divided by zero'") else: div=num1/num2 print("num1/num2={}".format(div))
23rd Mar 2020, 2:25 PM
Muhammad Galhoum
Muhammad Galhoum - avatar
+ 1
Indentation defines a code block. Code within a while loop is not surrounded with brackets, it just continues the same indentation. So: while True: #this is inside the 'while' block #so is this. #this too. #This is not because the indentation is back to normal. Your code starts: while True: print('Options') #This is within 'while' block print('Enter ...') #This is no longer within the block because there's no indentation. Everything after this is, of course, also not within the 'while' block, so your 'break' statement is not within a 'for' or 'while' loop, so there's nothing for it to break out from.
23rd Mar 2020, 3:09 PM
Russ
Russ - avatar
0
Your code arrangements is wrong
23rd Mar 2020, 2:05 PM
Jason
Jason - avatar
0
if user_input == "quit": break elif user_input == 'add': <-- This is your problem line! The elif line should start level with the if line. if user_input == "quit": break elif user_input == 'add': #code block starting with indent. elif...: #more code else: #more code Continue like this.
23rd Mar 2020, 2:13 PM
Russ
Russ - avatar
0
Thank you for the answers
23rd Mar 2020, 2:18 PM
Mubashir M
Mubashir M - avatar
0
Hey guys I tried again and now its saying 'break' outside loop What does that mean
23rd Mar 2020, 2:35 PM
Mubashir M
Mubashir M - avatar
0
Sorry if I'm firing a lot of questions in one post
23rd Mar 2020, 2:36 PM
Mubashir M
Mubashir M - avatar
0
here's the code now: while True: print('Options:') print('Enter add to add two numbers') print('Enter minus to subtract two numbers') print('Enter multiply to multiply two numbers') print('Enter divide to divide two numbers') print('Enter quit to exit the calculator') user_input = input(":") if user_input == "quit": break elif user_input == 'add': num1 = float(input('Enter a number')) num2 = float(input('Enter another number')) result = str(num1 + num2) print('THE ANSWER IS' + result) elif user_input == 'minus': num1 = float(input('Enter a number')) num2 = float(input('Enter another number')) result = str(num1 - num2) print('THE ANSWER IS' + result) elif user_input == 'multiply': num1 = float(input('Enter a number')) num2 = float(input('Enter another number')) result = str(num1 * num2) print('THE ANSWER IS' + result) elif user_input == 'divide': num1 = float(input('Enter a number')) num2 = float(input('Enter another number')) result = str(num1 / num2) print('THE ANSWER IS' + result) else: print("ERROR 404") print("Thank you for using eCalc")
23rd Mar 2020, 2:38 PM
Mubashir M
Mubashir M - avatar
0
I have created my calculator: eCalc. Thank you for helping me out.
24th Mar 2020, 3:30 PM
Mubashir M
Mubashir M - avatar