Created
June 29, 2020 12:03
-
-
Save jdmedeiros/f20d62a81e5b3a27739677366aeb362d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def comparar(valor, inicio, fim): | |
if valor < inicio or valor > fim: | |
return True | |
while True: | |
try: | |
ano = int(input('Em que ano nasceste? ')) | |
if ano < 0: | |
raise ValueError | |
break | |
except ValueError: | |
print('Insere uma valor válido para o ano') | |
while True: | |
try: | |
mes = int(input('Em que mês nasceste? ')) | |
resultado = comparar(mes, 1, 12) | |
if resultado == True: | |
raise ValueError | |
break | |
except ValueError: | |
print('Insere uma valor válido para o mês') | |
diasMax = 31 | |
if mes in {4, 6, 9, 11}: | |
diasMax = 30 | |
if mes == 2: | |
if ano % 4 == 0: | |
diasMax = 29 | |
else: | |
diasMax = 28 | |
while True: | |
try: | |
dia = int(input('Em que dia nasceste? ')) | |
#if dia < 1 or dia > diasMax: | |
if comparar(dia, 1, diasMax): | |
raise ValueError | |
break | |
except ValueError: | |
print('Insere uma valor válido para o dia') | |
print('Então a tua data de nascimento é ', dia, '/', mes, '/', ano, sep='') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment