-2

this is my code, and when I input numbers that has two digits and one number that has only one digit, (e.g. when I input 47, 57, and 9) it results to 9 which is the smallest. please help.

def maximum(a, b, c):
        list = [a, b, c]
        return max(list)


num_one = input("Enter 1st Number: ")
num_two = input("Enter 2nd Number: ")
num_three = input("Enter 3rd Number: ")
num4 = 0

if num_one.isdecimal():
    if num_one.isdecimal():
        if num_one.isdecimal():
            a = num_one
            b = num_two
            c = num_three
            print(maximum(a, b, c))
        else:
            print("wrong input")
    else:
        print("wrong input")
else:
    print("wrong input")
AstroVon
  • 3
  • 1

1 Answers1

1

When you use input() it automatically takes in a string. So you have to convert it to a float or integer later. Also, the keyword and is useful instead of using three if statements:

def maximum(a, b, c):
    list = [a, b, c]
    return max(list)

num_one = input("Enter 1st Number: ")
num_two = input("Enter 2nd Number: ")
num_three = input("Enter 3rd Number: ")

if num_one.isdecimal() and num_two.isdecimal() and num_three.isdecimal():
    a = float(num_one)
    b = float(num_two)
    c = float(num_three)
    print(maximum(a, b, c))
else:
    print('Wrong input')
Tomerikoo
  • 18,379
  • 16
  • 47
  • 61
ph140
  • 478
  • 3
  • 10
  • 2
    Worth noting that `maximum` is just an unnecessary wrapper to the built-in `max`. i.e. doing `max(a, b, c)` will work exactly the same – Tomerikoo Jan 31 '21 at 18:17