-3
File "first.py", line 37
  elif(operation == "quadratic formula")
IndentationError: unindent does not match any outer indentation level

I really don't know what the problem is with my code. Can someone please help?

def add(var1, var2):
  return var1 + var2

def sub(num1, num2):
  return num1 - num2

def div(num1, num2):
    return num1/num2

def mul(num1,num2):
    return num1*num2
def equation1():
 import math

 a = int(raw_input("please enter your a in the equation: "))
 b = int(raw_input("please enter your b in the equation: "))
 c = int(raw_input("please enter your c in the equation: "))

 d = b**2-4*a*c 

 if(d < 0):
    print "This equation has no real solution"
 elif(d == 0):
    x = (-b+math.sqrt(b**2-4*a*c))/(2*a)
    print "This equation has one solutions: ", x
 else:
    x1 = (-b+math.sqrt(b**2-4*a*c))/(2*a)
    x2 = (-b-math.sqrt(b**2-4*a*c))/(2*a)
    print "This equation has two solutions"
    print "The first soluition: ", x1
    print "And the second solution", x2

def main():
    operation = raw_input("what do you want to do (+,-,/,*) or quadratic 
    formula? ")
    if(operation != '+' and operation != '-' and operation != '/' and operation != '*' and operation != 'quadratic formula'):
        print 'You must put a valid operation'
    elif( operation == "quadratic formula" ):
        equation1()
    else:
        var1 = int(raw_input("enter the first number:  " ))
        var2 = int(raw_input("enter the second number: "))
        if(operation == '+'):
            print (add(var1, var2))
        elif(operation == '/'):
            print (div(var1, var2))
        elif(operation == '-'):
            print (sub(var1, var2))
martineau
  • 119,623
  • 25
  • 170
  • 301

1 Answers1

0

The following shows your code in my text editor with tabs and space characters made visible and shown in the color red. As you can see, it indicates that you're using a mixture of them in it—and that's confusing the Python interpreter. Best to stick with one or the other, although I think 4 spaces are the best (and most portable).

You may be able to configure you editor to automatically convert tabs into the right number of spaces for you.

screenshot of code in editor

Update:

Since you still seem to be having problems, here's a version of your code in which I have removed the tab characters so now its indentation is comprised exclusively of 4 space characters for each level. See if you have better luck with it.

def add(var1, var2):
    return var1 + var2

def sub(num1, num2):
    return num1 - num2

def div(num1, num2):
    return num1/num2

def mul(num1,num2):
    return num1*num2

def equation1():
    import math

    a = int(raw_input("please enter your a in the equation: "))
    b = int(raw_input("please enter your b in the equation: "))
    c = int(raw_input("please enter your c in the equation: "))

    d = b**2-4*a*c

    if(d < 0):
        print "This equation has no real solution"
    elif(d == 0):
        x = (-b+math.sqrt(b**2-4*a*c))/(2*a)
        print "This equation has one solutions: ", x
    else:
        x1 = (-b+math.sqrt(b**2-4*a*c))/(2*a)
        x2 = (-b-math.sqrt(b**2-4*a*c))/(2*a)
        print "This equation has two solutions"
        print "The first soluition: ", x1
        print "And the second solution", x2

def main():
    operation = raw_input("what do you want to do (+,-,/,*) or quadratic formula? ")
    if(operation != '+' and operation != '-' and operation != '/' and operation != '*' and operation != 'quadratic formula'):
        print 'You must put a valid operation'
    elif( operation == "quadratic formula" ):
        equation1()
    else:
        var1 = int(raw_input("enter the first number:  " ))
        var2 = int(raw_input("enter the second number: "))
        if(operation == '+'):
            print (add(var1, var2))
        elif(operation == '/'):
            print (div(var1, var2))
        elif(operation == '-'):
            print (sub(var1, var2))
martineau
  • 119,623
  • 25
  • 170
  • 301