Home > Mobile >  Can you explain why none is printing in output?
Can you explain why none is printing in output?

Time:01-19

def great(a,b,c):
    if(a>b and a>c):
        print("a is greater")
    elif(b>a and b>c):
        print("b is greater")
    else:
        print("c is greater")
        a=great(12,3,1)
        print(a)

Can you explain why none is printing in output?

CodePudding user response:

In python indentation matters, Your Function Call is not Properly indented that is why it is not printing anything

def great(a,b,c):
    if(a>b and a>c):
        print("a is greater")
    elif(b>a and b>c):
        print("b is greater")
    else:
        print("c is greater")
a=great(12,3,1)
print(a)

CodePudding user response:

Because your great function is returning None.

Here is the solution:

def great(a,b,c):
    if(a>b and a>c):
        print("a is greater")
    elif(b>a and b>c):
        print("b is greater")
    else:
        print("c is greater")
great(12,3,1)

CodePudding user response:

function great() does not return anything. In python, when nothing is returned in a function, a default 'None' value is returned. So when use:

a=great(12,3,1)

it returns None value. That value is assigned to a. Therefore, when you print a you get None.

Check out this link for more:

https://realpython.com/python-return-statement/#:~:text=Implicit return Statements,-A Python function&text=That default return value will always be None .&text=If you don't supply,None as a return value.

  •  Tags:  
  • Related