forked from souravjain540/Basic-Python-Programs
-
Notifications
You must be signed in to change notification settings - Fork 1
/
calendar_program.py
33 lines (27 loc) · 997 Bytes
/
calendar_program.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
import calendar
'''
Write a Python program that prints the calendar of a given month in a given year after validating the user input.
'''
def validate_user_input():
is_valid_year = False
is_valid_month = False
'''user should enter a valid year'''
while not is_valid_year:
year = input("Enter the year \n format: YYYY: ")
if len(year) == 4 and year.isdigit():
is_valid_year = True
else:
print("Kindly Enter a vaild four-digit year number")
'''user should enter a valid month'''
while not is_valid_month:
month = input("Enter month \n format: 1-12: ")
if month.isdigit() and 12 >= int(month) >= 1:
is_valid_month = True
else:
print("Kindly Enter a vaild month number between 1 and 12")
return [int(year), int(month)]
def print_given_month():
year, month = validate_user_input()
print(year, month)
print(calendar.month(year, month))
print_given_month()