Number comparison to find max/min in python

后端 未结 3 1977
再見小時候
再見小時候 2021-01-28 04:51

I am a beginner in python. I have written a simple program to find greatest of 3 numbers. I get the right answer when I give input numbers having same number of digits (Eg. 50 8

3条回答
  •  一向
    一向 (楼主)
    2021-01-28 05:42

    If you don't want TimTom's (no max()), here is another way:

    num1= int("Enter 3 Number\n")
    num2= int(input())
    num3= int(input())
    
    if num1 >= num2 and num1 >= num3:
       numLarge = num1
    #  print exchange
    elif num2 >= num1 and num2 >= num3:
       numLarge = num2
    #  print exchange
    else:
       numLarge = num3
    #  print exchange
    
    print("The greatest is " + str(numLarge))
    

提交回复
热议问题