I need help adding classes to a patically completed python program. The program needs to take a list of dates and events, turn the date
I need help adding classes to a patically completed python program.
The program needs to take a list of dates and events, turn the date format into a canonical form, and then take that info and place it into objects. I need two different clasess that are described in this screencap:
The code I have is as follows:
def readFile():
file = input()
date_str=[]
for words in file:
date_str.append(words.split())
return date_str
def commandFile(date_str):
L=[];
Z=[];
for line in date_str:
if line[0] is 'I':
s="";
date=canonicalize_date(line);
if('-' in line[1]):
for i in range(0,len(line)):
if i>2:
s=s+" "+line[i];
elif '/' in line[1]:
for i in range(0,len(line)):
if i>2:
s=s+" "+line[i];
else:
for i in range(0,len(line)):
if i>4:
s=s+" "+line[i];
temp=list();
temp.append(date);
temp.append(s);
L.append(temp);
elif line[0] is 'R':
temp_date=canonicalize_date(line);
for i in L:
if temp_date==i[0]:
print(temp_date, i[1])
def canonicalize_date(line):
yyyy="";
dd="";
mm="";
date_str=line[1];
if '-' in date_str:
d=date_str.split('-')
yyyy=d[0]
dd=d[2]
mm=d[1]
elif '/' in date_str:
d=date_str.split('/')
yyyy=d[2]
dd=d[1]
mm=d[0]
else:
d_index= line[1]
month ={'Jan':1,'Feb':2,'Mar':3,'Apr':4,'May':5,'Jun':6,'Jul':7,'Aug':8,'Sep':9,'Oct':10,'Nov':11,'Dec':12};
dd = line[2]
yyyy=line[3]
mm=month[d_index]
scheme = "{:d}-{:d}-{:d}".format(int(yyyy), int(mm), int(dd))
return scheme
def main():
date_str=readFile()
commandFile(date_str)
main()
Example test 1:
Input:
I 1960-02-27 : U.S. Olympic hockey team beats Soviet Union I 1897-2-27 : Britain recognizes U.S. authority over Western Hemisphere I Apr 5 1974 : World Trade Center, then the world's tallest building, opens in New York I 1946-1-10: UN General Assembly meets for 1st time (London) R Feb 27 1960 I 3/4/1861 : Abraham Lincoln is inaugurated as 16th US President I 4/5/1242: Alexander Nevsky of Novgorod defeats Teutonic Knights in the Battle of the Ice I Apr 5 1879 : Chile declares war on Bolivia and Peru, starting the War of the Pacific R 1879-04-05 I 6/25/1667 : First blood transfusion performed by French Doctor Jean-Baptiste Denys I 1876-06-25 : Battle of the Little Bighorn R 6/25/1876 I Jul 20 1881 : Sioux Indian Chief Sitting Bull, surrenders to US federal troops I Jul 20 1921: Congresswoman Alice Mary Robertson becomes the first woman to preside over the US House of Representatives I 1954-07-20: Armistice for Indo-China signed, Vietnam separates into North & South I 1969-7-20: 1st Moon Landing: Neil Armstrong and Buzz Aldrin from Apollo 11 R 7/20/1921 R 07/20/1969 R Jul 20 1954
Output:
1960-2-27: U.S. Olympic hockey team beats Soviet Union 1879-4-5: Chile declares war on Bolivia and Peru, starting the War of the Pacific 1876-6-25: Battle of the Little Bighorn 1921-7-20: Congresswoman Alice Mary Robertson becomes the first woman to preside over the US House of Representatives 1969-7-20: 1st Moon Landing: Neil Armstrong and Buzz Aldrin from Apollo 11 1954-7-20: Armistice for Indo-China signed, Vietnam separates into North & South
Example test 2:
Input:
I 2017-01-01 : New Year's Day I Jan 1 2017 : New Year party R 2017-01-01
Output:
2017-1-1: New Year party 2017-1-1: New Year's Day
Your program should implement the following classes: class Date An instance of this class describes a date Attributes: These should include the canonical representation of the date the associeted events (a collection of strings, eg., a list or set) Methods: These should include: init_(self, date, event), where date is the canonical representation of the date and event is a string for an event Getter methods for the attributes add_event (self, event), where event is a string for an event, this method adds event to the collection of events for a Date object str (self), which retums a string representation of a Date object class DateSet An instance of this class describes a collection of dates Attributes: These should include: a dictionary of Date objects. (Consider what might you use as keys.) Methods: These should include: init (self), hich creates an empty dictionary to hold Date objects add_date(self, date), where date is a date object, this method adds date to the collection of dates .str_(self), which retums a string representation of a DateSet object Your program should implement the following classes: class Date An instance of this class describes a date Attributes: These should include the canonical representation of the date the associeted events (a collection of strings, eg., a list or set) Methods: These should include: init_(self, date, event), where date is the canonical representation of the date and event is a string for an event Getter methods for the attributes add_event (self, event), where event is a string for an event, this method adds event to the collection of events for a Date object str (self), which retums a string representation of a Date object class DateSet An instance of this class describes a collection of dates Attributes: These should include: a dictionary of Date objects. (Consider what might you use as keys.) Methods: These should include: init (self), hich creates an empty dictionary to hold Date objects add_date(self, date), where date is a date object, this method adds date to the collection of dates .str_(self), which retums a string representation of a DateSet objectStep by Step Solution
There are 3 Steps involved in it
Step: 1
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started