-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathPalindrome Dates
120 lines (75 loc) · 3.24 KB
/
Palindrome Dates
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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
## Name: Jaewon Son
## Date: October 15 2023
## Honor Statement: I have not given or received any unauthorized assistance on this assignment.
## Link: https://youtu.be/KQdLfmQy13c
def date1():
"""Generate a list of dates in the DD/MM/YYYY format.
Returns:
list: Returns a list of dates for Jan, Mar, May, Jul, Aug. Oct, and Dec in the 21st century.
"""
month_with_31_days = ['01', '03', '05', '07', '08', '10', '12']
date_list1 = []
for year in range(2000, 2100):
for month in month_with_31_days:
for day in range(1, 32): # 31 days
date = f"{day}/{month}/{year}" # DD/MM/YYYY format
date = date.zfill(10) # Fixed as a 10-character string
date_list1.append(date)
return date_list1
def date2():
"""Generate a list of dates in the DD/MM/YYYY format.
Returns:
list: Returns a list of dates for Apr, Jun, Sep, and Nov in the 21st century.
"""
month_with_30_days = ['04', '06', '09', '11']
date_list2 = []
for year in range(2000, 2100):
for month in month_with_30_days:
for day in range(1, 31): # 30 days
date = f"{day}/{month}/{year}" # DD/MM/YYYY format
date = date.zfill(10) # Fixed as a 10-character string
date_list2.append(date)
return date_list2
def date3():
"""Generate a list of dates in the DD/MM/YYYY format.
Returns:
list: Returns a list of dates for Feb in the 21st century.
"""
month_with_28_days = ['02']
date_list3 = []
for year in range(2000, 2100):
for month in month_with_28_days:
for day in range(1, 29): # 28 days
date = f"{day}/{month}/{year}" # DD/MM/YYYY format
date = date.zfill(10) # Fixed as a 10-character string
date_list3.append(date)
return date_list3
def palindrome_date(date_list):
"""Test if a date is a palindrome date.
Returns:
list: Returns a list of palindrome dates.
"""
palindrome_date_list = []
for date in date_list: # Checking whether a date is a palindrome or not.
if date[0] == date[9]:
if date[1] == date[8]:
if date[3] == date[7]:
if date[4] == date[6]:
palindrome_date_list.append(date)
return palindrome_date_list
def write_text_file(palindrome_dates_list):
"""Write palindrome dates to a text file.
"""
palindrome_dates_list_file = open(r"C:\Users\LG\Desktop\DEPAUL UNIV\2023 Fall\Python Programming\DSC 430 - Week 6\JaewonSon_Assignment_0601_Palindrome_Dates.txt", 'w')
for palindrome_dates in palindrome_dates_list:
palindrome_dates_list_file.write(f"{palindrome_dates}\n") # Write palindrome dates into a separate line
palindrome_dates_list_file.close()
def main():
"""Main function for the Palindrome Dates.
"""
date_list = date1() + date2() + date3()
date_list.sort()
palindrome_date_list = palindrome_date(date_list)
write_text_file(palindrome_date_list)
if __name__ == "__main__":
main()