Home > database >  None value in a return function
None value in a return function

Time:10-31

I had to write a function in Python that returns the highest number of three integer numbers (as arguments), it seemed to easy to me, but proving this in Spyder and VSC, the output is None. I don't understand the reason because the input are three integer numbers.

def max_tres_num(a,b,c):
    if a>=b and a>=c:
        return a
    if b>=a and b>=c:
        return b
    if c>=a and c<=b:
        return c
    
print(max_tres_num(1, 2, 3))
> None

I tried this code, otherwise I can't discover the reason of the None value or an another way to do it.

CodePudding user response:

You made an error while writing the program where in last condition you put '<' sign rather than '>' sign.

def max_tres_num(a,b,c):
    if a>=b and a>=c: 
        return a 
    if b>=a and b>=c: 
        return b 
    if c>=a and c>=b: 
        return c

print(max_tres_num(1, 2, 3))

This should work now

  • Related