Jump to content

Python being strange?!?!?!

digitaldoughnut
Go to solution Solved by fizzlesticks,

Your indention is wrong, the line above the if is double indented. The amount you indent doesn't matter but you have to be consistent. Also you need double equals == to compare values and the strings you're comparing to need quotes.

 

And in the future please use code tags.

I have written this piece of code, its basically a calculator and when i try to run the code in python it give me this error: "unindent does not match any outer indentation level" 

it was working before but now it won't work does anyone have any ideas why???

thanks :) 

 


def subtract(first,second):
    print(first-second)
def add(first,second):
    print(first+second)
def divide(first,second):
    print(first/second)
def multiply(first,second):
    print(first*second)
def exponential(first,second):
    print(first**second)


#This is the main program
carryon = False
while not carryon:
        option = input("s to subtract /nor a to add/nor d to divide /nor d to divide /nor e to exponential /nor q to quit")

    if option = s:      <<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<*****(THIS IS THE LINE THAT PYTHON DOESN"T LIKE!!!)*****
            one = int(input("Enter a number")
            two = int(input("Enter a second number")
            subtract(first,second)

    elif option = a:
            one = int(input("Enter a number")
            two = int(input("Enter a second number")
            add(first,second)

    elif option = d:
            one = int(input("Enter a number")
            two = int(input("Enter a second number")
            divide(first,second)

    elif option = m:
            one = int(input("Enter a number")
            two = int(input("Enter a second number")
            multiply(first,second)

    elif option e:
            one = int(input("Enter a number")
            two = int(input("Enter a second number")
            exponential(first,second)

    elif option = q:
                  carryon = True
    else:
                  print("Enter numbers as you have not entered a valid number")
        

Link to comment
Share on other sites

Link to post
Share on other sites

Your indention is wrong, the line above the if is double indented. The amount you indent doesn't matter but you have to be consistent. Also you need double equals == to compare values and the strings you're comparing to need quotes.

 

And in the future please use code tags.

1474412270.2748842

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×