None return problem in python

Asked

Viewed 156 times

1

I’m doing an exercise in Python and I don’t understand why the output is coming back with None together, I thank you

def main(x,nomePlaneta) :
  if nomePlaneta == "Terra" : 
    valordois =  x//86400
    valortres = (x%86400)//3600
    valorquatro = ((x%86400)%3600)//60
    valorcinco = ((x%86400)%3600)%60

  elif nomePlaneta == "Jupiter":
    valordois =  x//35760
    valortres = (x%35760)//3600
    valorquatro = ((x%35760)%3600)//60
    valorcinco =  ((x%35760)%3600)%60
  elif nomePlaneta == "Venus" :
    valordois =  x//20995200
    valortres = (x% 20995200)// 3600
    valorquatro = ((x% 20995200)% 3600)//60
    valorcinco = ((x% 20995200)% 3600)%60  
  elif nomePlaneta == "Mercurio" :
    valordois =  x// 5068800
    valortres = (x%  5068800)// 3600
    valorquatro = ((x% 5068800)%  3600)//60
    valorcinco = ((x% 5068800)%  3600)%60

  print(x, 'segundos no planeta Terra equivalem a:')
  print(valordois, 'dias,',valortres, 'horas,',valorquatro, 'minutos e',valorcinco ,'segundos')

lista = input().split()

valor1 = int(lista[0])
nomePlaneta = str(lista[1])

print(main(valor1,nomePlaneta))
  • Solved, had researched and found in some similar problems, that this happens when you call the function itself within the function. In case he was putting print inside print. To solve, I only modified the last print(main(value1,namePlaneta)) by main(value1,namePlaneta) and there it was correct

1 answer

2

In fact you were printing the return of the function main() (the print(main(...))), but this function writes several things but returns no value. There is no return in the end passing values to those who called her, but as she finished without mistakes she returns the None (the default in Python).

Browser other questions tagged

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