COMP2152 Assignment 2 (Group Assignment) Due: April 18, 2021, 11:59 PM Late penalty: 10% per day of lateness, to a maximum of 3 days. Assignments not accepted after that time. Groups: Students have...

1 answer below »
I'm looking for someone to complete my Python assignment.


COMP2152 Assignment 2 (Group Assignment) Due: April 18, 2021, 11:59 PM Late penalty: 10% per day of lateness, to a maximum of 3 days. Assignments not accepted after that time. Groups: Students have the opportunity to create groups of 3 maximum. Single student submissions are also possible. Hand in: Submission is to be done in 3 places: · Blackboard · GBLearn FTP Account · MyGBLearn On Blackboard: Submit a text submission of 1. the members of the group 2. the URL location of the Calendar.py file (to be hosted on the GBLearn account of one of the members of the group) On GBLearn: Submit the 1. Calendar.py source file 2. a text file of the members of the group. Path: /public_html/comp2152/assignments/assignment2 Marking: Your code will be automarked for functionality by using unit testing test cases. We will also use software to detect plagiarism. · Download Calendar.py · Complete all functions so that they behave as described. · Make sure that the DocTest code successfully runs. You might want to add even more test cases. · You do not need to define any new functions. However, you may optionally choose to do so. · Do not use any additional packages or libraries. Questions and Answers Question: How do I open a file for reading if it exists, otherwise create it. Answer: Take a look at os.path.exists. You will need to import os at the top of Calendar.py. Example: import os if os.path.exists('zz'): print("File zz exists") else: print("File zz does not exists") Question: Can I make calendar = {} global? Answer: No, there is no global code!! The only 'global' thing is the new import os at the top of the Calendar.py file. Question: Can I doctest load_calendar and save_calendar? Answer: Yes, how about making a calendar and then saving it, then loading it back and finally comparing what you saved and what you loaded. This requires that both functions work. There are other alternatives. This does not verify the file format, but does verify that save and load work together properly. Question: Can I use functions like is_natural_number inside other functions? Answer: Yes, definitely, better code repeats less. If you define a useful function, you should use it everywhere it makes sense to use it. Question: For the function is_command(command), do we need to account that the commands could be upper case (e.g. "Add", "Delete") or can we just assume that all commands will be lower case? Answer: We will not mark it wrong if you accept or reject mixed case commands. You must accept lowercase commands. Question: Are the test cases in the program the only ones that will be accounted for, or should be try out more test cases to make sure it works completely? Answer: A tester will be released before the deadline. The tester will outline all the final test cases that will determine your mark. Question: Are we allowed to use the isdigit method in the is_natural_number function? Answer: Please do not use isdigit. Question: For user_interface(), should we make test cases for it or should we assume that the user will always enter parameters correctly? Answer: The user may enter nonsense. You do not have to write test cases for this function. Question: Can I be group members with students in a CRN that is not my lab class? Answer: Students should create groups within their lab class. If this is not the case, there will be a penalty assessed to their work. This penalty is to be determined and will be outlined in the feedback. Question: Must all group members submit the final project? Answer: One group member may submit the project. Ensure that you communicate so there is at least one submission. If submissions from multiple group members are found, only the first one will be marked. If one group member submits multiple submissions, the latest submission will be marked. Question: I don't see Assignment 2 on My.GBLearn.com Answer: It has recently been added. Please check again. import urllib.request url = "http://comp2152.gblearn.com/2021/winter/a2_tester_calendar.php" tester_file = urllib.request.urlopen(url) exec(tester_file.read()) import urllib.request url = "http://comp2152.gblearn.com/2021/winter/a2_tester_user_interface.php" tester_file = urllib.request.urlopen(url) exec(tester_file.read())
Answered Same DayApr 17, 2021

Answer To: COMP2152 Assignment 2 (Group Assignment) Due: April 18, 2021, 11:59 PM Late penalty: 10% per day of...

Pulkit answered on Apr 18 2021
152 Votes
81015_python/Calendar.py
import os
'''
IMPORTANT NOTE: Do NOT change any of the function names or their signatures
(the parameters they take).
Your functions must behave exactly as described. Please check correctness by
running DocTests included in function headers. You may not use any print or
input statements in your code.
Manage a calendar database.
A calendar is a dictionary keyed by date ("YYYY-MM-DD") with value being a list
of strings, the events on the specified date.
'''
# -----------------------------------------------------------------------------
# Please implement the following calendar commands

# -----------------------------------------------------------------------------
def command_help():
"""
() -> str
This function is already implemented. Please do not change it.
Returns a help message for the system. That is...
"""
help_me = """
Help for Calendar. The calendar commands are
add DATE START END DETAILS add the event DETAILS at the specified DATE with specific START and END time
show show all events in the calendar
delete DATE NUMBER delete the specified event (by NUMBER) from
the calendar
quit quit this program
help display this help message
Examples: user data follows command:
command: add 2018-10-12 18 19 dinner with jane
success
command: show
2018-10-12 :
start : 08:00,
            end : 09:00,
            title : Eye doctor
            
start : 12:30,
            end : 13:00,
            title : lunch with sid

            start : 18:00,
            end : 19:00,
            title : dinner with jane
2018-10-29 :
start : 10:00,
            end : 11:00,
            title : Change oil in blue car
            
start : 12:00,
            end : 14:00,
            title : Fix tree near front walkway
            
start : 18:00,
            end : 19:00,
            title : Get salad stuff, leuttice, red peppers, green peppers
2018-11-06 :
start : 18:00,
            end : 22:00,
            title : Sid's birthday
command: delete 2018-10-29 10
deleted
A DATE has the form YYYY-MM-DD, for example
2018-12-21
2016-01-02
START and END has a format HH where HH is an hour in 24h format, for example
09
21
Event DETAILS consist of alphabetic characters,
no tabs or newlines allowed.
"""
return help_me
def command_add(date, start_time, end_time, title, calendar):
"""
(str, int, int, str, dict) -> boolean
Add title to the list at calendar[date]
Create date if it was not there
Adds the date if start_time is less or equal to the end_time
date: A string date formatted as "YYYY-MM-DD"
start_time: An integer from 0-23 representing the start time
end_time: An integer from 0-23 representing the start time
title: A string describing the event
calendar: The calendar database
return: boolean of whether the even was successfully added
>>> calendar = {}
>>> command_add("2018-02-28", 11, 12, "Python class", calendar)
True
>>> calendar == {"2018-02-28": [{"start": 11, "end": 12, "title": "Python class"}]}
True
>>> command_add("2018-03-11", 14, 16, "CSCA08 test 2", calendar)
True
>>> calendar == {"2018-03-11": [{"start": 14, "end": 16, "title": "CSCA08 test 2"}], \
"2018-02-28": [{"start": 11, "end": 12, "title": "Python class"}]}
True
>>> command_add("2018-03-11", 10, 9, "go out with friends after test", calendar)
False
"""
if start_time > end_time:
return False

# Add the date with an empty list as its value if it is not already in the database and start time is less than end time
if date not in calendar and start_time <= end_time:
calendar[date] = []

# Add the title to the list at calendar[date] with the start and end time
calendar[date].append({"start":start_time, "end": end_time, "title": title})
return True
def command_show(calendar):
r"""
(dict) -> str
Returns the list of events for calendar sorted in decreasing date order
and increasing time order within the date
as a string, see examples below for a sample formatting
calendar: the database of events
Example:
>>> calendar = {}
>>> command_add("2018-01-15", 11, 13, "Eye doctor", calendar)
True
>>> command_add("2018-01-15", 8, 9, "lunch with sid", calendar)
True
>>> command_add("2018-02-10", 12, 23, "Change oil in blue car", calendar)
True
>>> command_add("2018-02-10", 20, 22, "dinner with Jane", calendar)
True
>>> command_add("2017-12-22", 5, 8, "Fix tree near front walkway", calendar)
True
>>> command_add("2017-12-22", 13, 15, "Get salad stuff", calendar)
True
>>> command_add("2018-05-06", 19, 23, "Sid's birthday", calendar)
True
>>> command_show(calendar)
"\n2018-05-06 : \n start : 19:00,\n end : 23:00,\n title : Sid's birthday\n2018-02-10 : \n start : 12:00,\n end : 23:00,\n title : Change oil in blue car\n\n start : 20:00,\n end : 22:00,\n title : dinner with Jane\n2018-01-15 : \n start : 08:00,\n end : 09:00,\n title : lunch with sid\n\n start : 11:00,\n end : 13:00,\n title : Eye doctor\n2017-12-22 : \n start : 05:00,\n end : 08:00,\n title : Fix tree near front walkway\n\n start : 13:00,\n end : 15:00,\n title : Get salad stuff"
"""
for dt in sorted (calendar, reverse = True):
print (dt)
lst = calendar[dt]
lst = sorted (lst, key = lambda x:x["start"])
for appt in lst:
s = " start: " + str (appt["start"]) + ":00 "+"\n" + " end: " + str (appt["end"]) + ":00,\n"
s += " title: " + appt["title"] + "\n"
return s
def command_delete(date, start_time, calendar):
"""
(str, int, dict) -> str
Delete the entry at calendar[date][start_time]
If calendar[date] is empty, remove this date from the calendar.
If the entry does not exist, do nothing
date: A string date formatted as "YYYY-MM-DD"
start_time: An...
SOLUTION.PDF

Answer To This Question Is Available To Download

Related Questions & Answers

More Questions »

Submit New Assignment

Copy and Paste Your Assignment Here