-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQ8 read dates from input, one date per line.py
More file actions
57 lines (53 loc) · 1.73 KB
/
Copy pathQ8 read dates from input, one date per line.py
File metadata and controls
57 lines (53 loc) · 1.73 KB
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
# Complete main() to read dates from input, one date per line.
# Each date's format must be as follows: March 1, 1990.
# Any date not following that format is incorrect and should beignored.
# Use the substring() method to parse the string and extract the date.
# The input ends with -1 on a line alone. Output each correct date as: 3/1/1990.
# Ex. if input is: March 1, 1990 April 2, 1995 7/15/20 December 13, 2003 -1
# The output is: 3/1/1990 12/13/2003
def get_month_as_int(month_str):
if month_str == 'January':
month_int = 1
elif month_str == 'February':
month_int = 2
elif month_str == 'March':
month_int = 3
elif month_str == 'April':
month_int = 4
elif month_str == 'May':
month_int = 5
elif month_str == 'June':
month_int = 6
elif month_str == 'July':
month_int = 7
elif month_str == 'August':
month_int = 8
elif month_str == 'September':
month_int = 9
elif month_str == 'October':
month_int = 10
elif month_str == 'November':
month_int = 11
elif month_str == 'December':
month_int = 12
else:
month_int = 0
return month_int
def main():
user_str = []
status = True
while(status == True):
user_str.append(input())
if (user_str[-1] == '-1'):
status = False
for strings in user_str:
if(',' in strings):
month_str = strings.split(',')[0].split()[0]
month_int = str(get_month_as_int(month_str))
date = strings.split(',')[0].split()[1]
year = strings[-4:]
final_date = month_int + '/' + date + '/' + year
print(final_date)
else:
pass
main()