Python 3 - Birth Date Problems

Asked

Viewed 1,292 times

0

Good evening, the code below in python3 should return a monthly fee amount according to the customer’s age, I used the time module to get the customer’s age when he informed his birth year, thinking about the possibility of the user to inform a year of birth higher than the current one, I put the following return:

"elif idade < 0:
   print('##ERRO## INFORME ANO VALIDO!') "

However it returns the value of R $ 50.00...

Can someone offer a help??

Terminal com a demonstração do código em execução

2 answers

1


One observation to make: method used to calculate the age of the person is not correct, as it must make the complete check with the day and month of birth.

In your condition, you start by checking whether the age is equal to or less than 18.

if idade <= 18:

Where the problem is, you should also check if age is greater than 0.

if idade >= 0 and idade <= 18:

See working on repl it.

  • Thanks, it worked, one more being betrayed by the small details.. m/

-1

On line 11 should be:

if(idade >= 0 and idade <= 18):

On line 21:

else:

Browser other questions tagged

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