How to solve the None problem in PYTHON

Asked

Viewed 1,861 times

0

For example I have this program:

def bissexto (inicio,fim):
    """Diz quais são os anos bissextos"""
    for i in range (inicio,fim+1):
        if(i %4==0 and i %100!=0) or i %400==0:
            print(i,"- Bissexto")
        else:
            print(i,"- Não é bissexto")
inicio=int(input("Digite o primeiro ano"))
fim=int(input("Digite até quando quer saber"))
print(bissexto(inicio,fim))

Where the exit is:

2000 - Bissexto
2001 - Não é bissexto
2002 - Não é bissexto
2003 - Não é bissexto
2004 - Bissexto
2005 - Não é bissexto
2006 - Não é bissexto
2007 - Não é bissexto
2008 - Bissexto
2009 - Não é bissexto
2010 - Não é bissexto
None

How can I solve this problem of appearing None in my program?

  • 2
    1. Do not post code as image; 2) Its function shall be bissexto has no return, soon will be None, in making print(bissexto(inicio, fim)) you are having the function return display, None.
    1. Sorry I put images to show lines of code, already solved this problem 2)Thanks, I managed to solve the problem

1 answer

3


"None" only appears because you, in the last line, call the function bissexto, and prints the return value of the same.

Since she doesn’t have a command return explicit, it returns None, and its print prints that None.

Since your function prints itself everything you want to see in the program, and does not generate a return value that you will use, just exchange your last line for:

bissexto(inicio,fim)

Browser other questions tagged

You are not signed in. Login or sign up in order to post.