I'm in the very early stages of learning python at the moment and can't figure out what's wrong with this code.
The function is supposed to return the larger of the 2 numbers that are inputted, but it will often return the smaller of the values and I can't find the problem in the code and can't find a pattern in when the wrong value is returned.
I'm probably doing something really basic wrong, but I thought I'd ask because I can't for the life of me figure this out.
def findMax(x, y):
if x > y:
return("max1: " + x)
elif y > x:
return("max2: " + y)
else:
return("numbers are equal")
x = input("x: ")
y = input("y: ")
print(findMax(x, y))
Some examples of input and outputs:
x: 10
y: 5
max2: 5
x: 5
y: 10
max1: 5
x: 7
y: 4
max1: 7
x: 4
y: 7
max2: 7
x: 7
y: 10
max1: 7
x: 10
y: 7
max2: 7
Aucun commentaire:
Enregistrer un commentaire