-3
def max(num1,num2,num3):
    if num1 > num2 and num1 > num3:
        return num1
    elif num2 > num1 and num2 > num3:
        return num2
    elif num3 > num1 and num3 > num2:
        return num3
    elif num1 == num2 == num3:
        return num1 == num2 == num3
    else:
        print("something went wrong.")

print(max(4,5,8))

I am a basic python programmer learning python,i have tried to define a function which prints out maximum of a three number,but how to use the input function to get the number as input.

001
  • 13,291
  • 5
  • 35
  • 66
  • 3
    Simplest: `first_number = int(input("Enter #"))` Repeat for next 2 numbers. [How can I read inputs as numbers?](https://stackoverflow.com/a/20449433) – 001 Sep 10 '21 at 17:43

1 Answers1

0

you can just use something like

we are using int function because input function takes the number or string and makes it a string so we need integer version of them so we can compare them

num1 = int(input("what is your first number: "))
num2 = int(input("what is your second number: "))
num3 = int(input("what is your third number: "))

but it can give errors because you did not use try except so the proper way is

while True:
    try:
        num1 = int(input("what is your first number: "))
        num2 = int(input("what is your second number: "))
        num3 = int(input("what is your second number: "))
    except:
        print("give me integer or number or i do not know what type of data do you want")
    else:
        break

you can change what is in the last print statement

you can use that it is still impovable you should check assert

i hope it is helpful