-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDisplayCalander.py
59 lines (49 loc) · 1.52 KB
/
DisplayCalander.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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
import calendar
from colorama import Fore, Style
from utils.terminal_utils import clear_terminal;
from utils.retry_utils import retry;
clear_terminal()
print(f"{Fore.GREEN}Welcome to Display Calendar Program{Style.RESET_ALL}")
# Function to get valid year input
def get_year():
while True:
try:
year = int(input("Enter year: "))
return year
except ValueError:
print(
f"{Fore.RED}Invalid input! Please enter a valid year (numbers only).{Style.RESET_ALL}"
)
retry()
# Function to get valid month input
def get_month():
while True:
try:
month = int(input("Enter month (1-12): "))
if 1 <= month <= 12:
return month
else:
print(
f"{Fore.RED}Invalid input! Please enter a month between 1 and 12.{Style.RESET_ALL}"
)
except ValueError:
print(
f"{Fore.RED}Invalid input! Please enter a valid month (numbers only).{Style.RESET_ALL}"
)
retry()
# Generate and display the calendar
def generate_and_display_calander():
# Get valid inputs
year = get_year()
month = get_month()
clear_terminal()
cal = calendar.month(year, month)
print(cal)
try:
while True:
generate_and_display_calander()
retry()
except KeyboardInterrupt:
print(
f"\n {Fore.YELLOW} Program interrupted. {Fore.GREEN}Exiting gracefully...{Style.RESET_ALL}"
)