Untitled

mail@pastecode.io avatar
unknown
plain_text
a month ago
997 B
66
Indexable
Never
def leap_year(y):
    if y % 400 == 0:
        return 1
    elif y % 100 == 0:
        return 0
    elif y % 4 == 0:
        return 1
    else:
        return 0

def number_of_days(m, y):
    l = leap_year(y)
    if m == 1 or m == 3 or m == 5 or m == 7 or m == 8 or m == 10 or m == 12:
        return 31
    elif m == 4 or m == 6 or m == 9 or m == 11:
        return 30
    elif m == 2:
        if l == 1:
            return 29
        elif l == 0:
            return 28

def days_passed(d, m, y):
    passed = 0
    for i in range(1, m):
        passed += number_of_days(i, y)
    return passed + d - 1

print("Please enter a date")
day = int(input("Day: "))
month = int(input("Month: "))
year = int(input("Year: "))
menu = int(input("Menu: \n1) Calculate the number of days in the given month. \n2) Calculate the number of days left in the given year. \n"))
if menu == 1:
    print(number_of_days(month, year))
elif menu == 2:
    print(days_passed(day, month, year))
else:
    print("Invalid.")
Leave a Comment