1
- # Program to display calendar
2
-
3
-
4
- def display_calendar (year , month ):
1
+ def display_cal (year_input , month_input ):
5
2
"""
6
- Display a calendar for the given year and month.
3
+ Display a calendar for the desired year and month.
7
4
8
5
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.
11
8
12
9
"""
13
10
import calendar
14
11
15
- print (calendar .month (year , month ))
12
+ print (calendar .month (year_input , month_input ))
16
13
17
14
18
- def get_valid_year ():
15
+ def fetch_year ():
19
16
"""
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.
21
18
"""
22
19
while True :
23
20
try :
24
- year = int (input ("Enter year: " ))
25
- if year < 0 :
21
+ year_input = int (input ("Enter year: " ))
22
+ if year_input < 0 :
26
23
raise ValueError ("Year must be a positive integer" )
27
- return year
24
+ return year_input
28
25
except ValueError :
29
26
print ("Invalid input. Please enter a valid year." )
30
27
31
28
32
- def get_valid_month ():
29
+ def fetch_month ():
33
30
"""
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.
35
32
"""
36
33
while True :
37
34
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 :
40
37
raise ValueError ("Month must be between 1 and 12" )
41
- return month
38
+ return month_input
42
39
except ValueError :
43
40
print ("Invalid input. Please enter a valid month." )
44
41
45
42
46
- year = get_valid_year ()
47
- month = get_valid_month ()
43
+ year_input = fetch_year ()
44
+ month_input = fetch_month ()
48
45
49
- display_calendar ( year , month )
46
+ display_cal ( year_input , month_input )
0 commit comments