/dias_mes.py Secret
Created
September 22, 2020 21:57
Star
You must be signed in to star a gist
This file contains 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
""" | |
https://parzibyte.me/blog | |
""" | |
def es_bisiesto(anio: int) -> bool: | |
return anio % 4 == 0 and (anio % 100 != 0 or anio % 400 == 0) | |
def obtener_dias_del_mes(mes: int, anio: int) -> int: | |
# Abril, junio, septiembre y noviembre tienen 30 | |
if mes in [4, 6, 9, 11]: | |
return 30 | |
# Febrero depende de si es o no bisiesto | |
if mes == 2: | |
if es_bisiesto(anio): | |
return 29 | |
else: | |
return 28 | |
else: | |
# En caso contrario, tiene 31 días | |
return 31 | |
# Probamos | |
mes = 9 | |
anio = 2020 | |
dias = obtener_dias_del_mes(mes, anio) | |
print(dias) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment