1- # Program to display calendar
2-
3-
4- def display_calendar (year , month ):
1+ def display_cal (year_input , month_input ):
52 """
6- Display a calendar for the given year and month.
3+ Display a calendar for the desired year and month.
74
85 Parameters:
9- year (int): The year for which the calendar is to be displayed.
10- month (int): The month for which the calendar is to be displayed.
6+ year_input (int): The year for which the calendar is to be displayed.
7+ month_input (int): The month for which the calendar is to be displayed.
118
129 """
1310 import calendar
1411
15- print (calendar .month (year , month ))
12+ print (calendar .month (year_input , month_input ))
1613
1714
18- def get_valid_year ():
15+ def fetch_year ():
1916 """
20- Function to prompt the user for a valid year input and return the valid year as an integer.
17+ Prompts the user for a valid year and returns the year as an integer.
2118 """
2219 while True :
2320 try :
24- year = int (input ("Enter year: " ))
25- if year < 0 :
21+ year_input = int (input ("Enter year: " ))
22+ if year_input < 0 :
2623 raise ValueError ("Year must be a positive integer" )
27- return year
24+ return year_input
2825 except ValueError :
2926 print ("Invalid input. Please enter a valid year." )
3027
3128
32- def get_valid_month ():
29+ def fetch_month ():
3330 """
34- A function that prompts the user to enter a month, validates the input, and returns the valid month.
31+ Function that asks the user to enter a month, validates the input, and returns the valid month.
3532 """
3633 while True :
3734 try :
38- month = int (input ("Enter month: " ))
39- if month < 1 or month > 12 :
35+ month_input = int (input ("Enter month: " ))
36+ if month_input < 1 or month_input > 12 :
4037 raise ValueError ("Month must be between 1 and 12" )
41- return month
38+ return month_input
4239 except ValueError :
4340 print ("Invalid input. Please enter a valid month." )
4441
4542
46- year = get_valid_year ()
47- month = get_valid_month ()
43+ year_input = fetch_year ()
44+ month_input = fetch_month ()
4845
49- display_calendar ( year , month )
46+ display_cal ( year_input , month_input )
0 commit comments