#!/usr/bin/env python3
import sys
import calendar
import datetime
def leap_year(year):
if calendar.isleap(year):
return 1
else:
return 0
def number_of_days(month, year):
_, num_of_days = calendar.monthrange(year, month)
return num_of_days
def days_left(year, month, day):
user_date = datetime.date(year, month, day)
end_of_year = datetime.date(year, 12, 31)
delta = end_of_year - user_date
return delta.days
if __name__ == "__main__":
print("Please enter a date")
print("Day:")
try:
day = int(input())
except ValueError:
print("Should be digit")
sys.exit()
if day > 31 or day < 1:
print("Wrong day.")
sys.exit()
print("Month:")
try:
month = int(input())
except ValueError:
print("Should be digit")
sys.exit()
if month > 12 or month < 1:
print("Wrong month.")
sys.exit()
print("Year:")
try:
year = int(input())
except ValueError:
print("Should be digit")
sys.exit()
print("Menu:")
print("1) Calculate the number of days in the given month.")
print("2) Calculate the number of days left in the given year.")
try:
choice = int(input())
except ValueError:
print("Should be digit")
sys.exit()
if choice < 1 or choice > 2:
print("Wrong choice.")
sys.exit()
if choice == 1:
print(number_of_days(month, year))
elif choice == 2:
print(days_left(year, month, day))
Comments
Leave a comment