Issue with python max number function
Question:
In the course I follow he made an example like this and when I applied it worked just fine but then when I added the input part myself it doesn’t give out the max number correctly.
def max_num(num1, num2, num3):
if num1 >= num2 and num1 >= num3:
return num1
elif num2 >= num1 and num2 >= num3:
return num2
else:
return num3
first = input('first number ')
second = input('second number ')
third = input('third number ')
print(max_num(first, second, third))
Answers:
Python’s input()
function returns a String (https://docs.python.org/3/library/functions.html#input)
You need to convert the number to int
or float
:
number = int(input('number '))
In the course I follow he made an example like this and when I applied it worked just fine but then when I added the input part myself it doesn’t give out the max number correctly.
def max_num(num1, num2, num3):
if num1 >= num2 and num1 >= num3:
return num1
elif num2 >= num1 and num2 >= num3:
return num2
else:
return num3
first = input('first number ')
second = input('second number ')
third = input('third number ')
print(max_num(first, second, third))
Python’s input()
function returns a String (https://docs.python.org/3/library/functions.html#input)
You need to convert the number to int
or float
:
number = int(input('number '))