BeginnersProblem BeginnersProblem - 3 months ago 13
Python Question

Python coding exercise

I have a function named orderInt passed three integers and returns true if the three int are in ascending order, otherwise false. Here's my code so far:

def orderInt(a, b, c):
print "Enter 3 integers: "
a = input()
b = input()
c = input()


How do I compare the variables?

Answer

First of all, your indentation is wrong.

def orderInt():
    print "Enter 3 integers: "
    a = input()
    b = input()
    c = input()
    if a<b<c:
        return True
    else:
        return False

print orderInt()

Second, your function is taking three arguments and also taking inputs. The arguments passed will be overwritten by your inputs.

def orderInt():
    print "Enter 3 integers: "
    if a<b<c:
        return True
    else:
        return False

a = input()
b = input()
c = input()

print orderInt(a,b,c)

Hope this helps.

Comments