Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Introduction to Python COMP100 Mo 10.00 UNIV199 We 12.00 COMP341 Th 12.00 MECH204 Mo 10.00 COMP 442 Mo 16.00 ENGR421 Mo 08.00 PSYC100 Fr 12.00

Introduction to Pythonimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed

COMP100 Mo 10.00 UNIV199 We 12.00 COMP341 Th 12.00 MECH204 Mo 10.00 COMP 442 Mo 16.00 ENGR421 Mo 08.00 PSYC100 Fr 12.00 HUMS120 Th 10.00 MAVA104 We 16.00 ECON201 We 12.00 MKTG201 Fr 10.00 PHYS102 Tu 14.00 ETHC113 Tu 08.00 INDR261 We 14.00 PSYC206 Fr 08.00 HIST300 Th 14.00 MATH102 Th 08.00 MBGE200 Fr 12.00 ELEC491 Tu 16.00 UNIV199 Introduction to Programming with Python Voluntary Homework Due: January 13, 2021, Thursday, 23:59. Files, Dictionaries and Lists: Plan Your Courses In this homework, you will plan your courses for the Spring semester by using the offered courses list. You are given the Hw VolCourses.txt file which consists of a course list that has course code, course day (first two letters), and time (like 10.00). Your program should do the following (please make sure you have read all the pdf before coding): 1- First, it should open the HwVolCourses.txt file and initialize the courses dictionary using the method initialize_dict(). Courses dictionary's keys will be the course codes. You are supposed to implement the values of this dictionary. You can figure out our implementation from the output. However, you are free to use other implementations as well. In the end, this dictionary should contain all the info in Hw VolCourses.txt. Note: initialize_dict() takes no parameters and returns a dictionary. 2- The program should check if there is a course_plan.txt file. If this file exists, you should read it and initialize my_plan. If the file does not exist, then you should create an empty dictionary for my_plan. In this dictionary, the day abbreviations (Mo', Tu', 'We', 'Th', 'Fr') should be the keys. For each day, the values should contain inner (nested) dictionaries. 3- Then, your program should ask the user what to do. User can add a course to their plan, remove a course from their plan or exit the program. 4- If the user chooses to add a course to their plan, your program should call add_course which does the following: This method takes two parameters; courses dictionary which has the info about the courses offered, and my_plan, which is the dictionary for the user's course program. It returns the updated version of my_plan. b. Then, it asks the user which course they want to add. After getting the course code, you should its day and time from the courses dictionary. By using this info, program should add the course to the user's plan and return it. However, you should check 3 things before doing that. i. If course code is not in the offered courses list, a message about it should appear and plan must remain unchanged. ii. If that course is already in the user's plan, a message about it should appear and plan must rema i unchanged. iii. If there is another course in the plan at the same day and time, a message about it with the conflicting course code should appear and plan must remain unchanged. a. a. 5. If the user chooses to remove a course from their plan, your program should call remove_course from the main function which does the following: This method takes two parameters; courses dictionary which has the info about the courses offered, and my_plan, which is the dictionary for the user's course program. It returns the updated version of my_plan. b. It asks the user which course they want to remove. After getting the course code, you should find its day and time from the courses dictionary. Your function should remove the course to the user's plan and return my_plan. However, you should check the following: i. If course code is not in the offered courses list, a message about it should appear and plan must remain unchanged. ii. If that course is not in the user's plan, a message about it should appear and plan must remain unchanged. 6- If the user chooses to exit, your program should call one last method, write_plan_to_txt. This method takes one parameter, user's plan and does not return anything. b. You should write user's plan to the course_plan.txt file. File format is as shown in the sample on the last page. You can write the list without sorting. 7- You are given helper functions in the starter file along with the methods you need to implement. You do not have to use these helper methods, but they might come in handy. Read their comments and implement and use them if you will. You can also add your own functions and do not use these at all. a. c. Make sure you place comments in your program. Place your name, ID and date the program was written as comments at the top. You should only use the features and commands you have learnt until this homework was given. Sample screen output is given on the next pages. Sample screen output: are This semester the offered courses {'COMP100': {'Day': 'Mo', 'Time': '10:00'), 'MECH204': {'Day': 'Mo', 'Time': '10:00'), 'COMP 442': {'Day': 'Mo', 'Time': '16:00'), 'ENGR421': {'Day': 'Mo', 'Time': '08:00'), 'PHYS102': {'Day': 'Tu', 'Time': '14:00'), 'ETHC113': {'Day': 'Tu', 'Time': '08:00'}, 'UNIV1 99': {'Day': 'We', 'Time': '12:00'}, "MAVA104': ''Day': 'We', 'Time': '16:00'}, 'ECON201': {'Day': 'We', 'Time': '12:00'), 'INDR261': {'Day': 'We', 'Time': '14:00'}, COMP341': {'Day': 'Th', 'Time': '12:00'}, "HUMS120': {'Day': 'Th', 'Time': '10:00'), 'HIST300': {'Day': 'Th', 'Time': '14:00'}, "MATH102': {'Day': 'Th', 'Time': '08:00'), 'PSYC100': {'Day': 'Fr', 'Time': '12:00'}, 'MKTG201': {'Day': 'Fr', 'Time': '10:00'}, "PSYC206': {'Day': 'Fr', 'Time': '08:00'}, 'MBGE 200': {'Day': 'Fr', 'Time': '12:00'}} Your choice: l-Add course 2-Remove course 3-Exit? 1 Which course do you want to add to your plan? PHYS102 Current plan is ('Mo': {}, 'Tu': {'14.00': 'PHYS102'}, "We': {), 'Th': {}, 'Fr': {}} Your choice: l-Add course 2-Remove course 3-Exit? 1 Which course do you want to add to your plan? PHYS102 You already have this course in your plan. Current plan is { 'Mo': {}, "Tu': {'14.00': 'PHYS102'}, 'We': {}, 'Th': {}, 'Fr': {}} Your choice: l-Add course 2-Remove course 3-Exit? 1 Which course do you want to add to your plan? UNIV199 Current plan is ('Mo': {}, 'Tu': {'14.00': 'PHYS102'}, 'We': {'12.00': 'UNIV199'), 'Th': {}, 'Fr': () Your choice: l-Add course 2-Remove course 3-Exit? 2 Which course do you want to remove from your current plan? COMP 341 Sorry, COMP341 is not currently in your plan. Current plan is ('Mo': {}, 'Tu': {'14.00': 'PHYS102'}, 'We': {'12.00': 'UNIV199'), 'Th': (), 'Fr': 0 Your choice: 1-Add course 2-Remove course 3-Exit? 1 Which course do you want to add to your plan? ELEC491 This course does not exist in the general course list. Current plan is {'Mo': {', 'Tu': {'14.00': 'PHYS102'}, 'We': {'12.00': 'UNIV199'), 'Th': {}, 'Fr': {}] Your choice: l-Add course 2-Remove course 3-Exit? 2 Which course do you want to remove from your current plan? MATH106 This course does not exist in the general course list. Current plan is { 'Mo': {}, 'Tu': {'14.00': 'PHYS102'}, 'We': {'12.00': 'UNIV199'), 'Th': {}, 'Fr': )) Your choice: l-Add course 2-Remove course 3-Exit? 1 Which course do you want to add to your plan? MATH102 Current plan is { 'Mo': [], "Tu': '14.00': "PHYS102'), 'We': {'12.00': 'UNIV199'), 'Th': {'08.00': 'MATH102'), 'Fr': {}} Your choice: l-Add course 2-Remove course 3-Exit? 2 Which course do you want to remove from your current plan? MATH102 Current plan is { 'Mo': {}, 'Tu': {'14.00': 'PHYS102'}, "We': {'12.00': 'UNIV199'), 'Th': {}, 'Fr': {}) Your choice: l-Add course 2-Remove course 3-Exit? 1 Which course do you want to add to your plan? HIST300 Current plan is { 'Mo': {}, "Tu': {'14.00': 'PHYS102'}, "We': {'12.00': 'UNIV199'), 'Th': {'14.00': 'HIST 300'}, 'Fr': {}} Your choice: l-Add course 2-Remove course 3-Exit? 1 Which course do you want to add to your plan? ECON201 Sorry, ECON201 is at the same time with UNIV199 Current plan is { 'Mo': {}, "Tu': {'14.00': 'PHYS102'), 'We': {'12.00': 'UNIV199'), 'Th': {'14.00': 'HIST300'), 'Fr': {}} Your choice: l-Add course 2-Remove course 3-Exit? 1 Which course do you want to add to your plan? ETHC113 Current plan is { 'Mo': {}, "Tu': {'14.00': 'PHYS102', '08.00': 'ETHC113'), 'We': {}, 'Th': {'14.00': 'HIST300'}, 'Fr': {}} Your choice: l-Add course 2-Remove course 3-Exit? 1 Which course do you want to add to your plan? ECON201 Current plan is { 'Mo': {}, "Tu': {'14.00': 'PHYS102', '08.00': 'ETHC113'}, "We': {'12.00': 'ECON201'}, 'Th': {'14.00': 'HIST300'}, 'Fr': {}} Your choice: 1-Add course 2-Remove course 3-Exit? 1 Which course do you want to add to your plan? COMP100 Current plan is {'Mo': {'10.00': 'COMP100'}, "Tu': {'14.00': 'PHYS102', '08.00': 'ETHC113'), 'We': {'12.00': 'ECON 201'}, 'Th': {'14.00': 'HIST300'), 'Fr': {}} Your choice: l-Add course 2-Remove course 3-Exit? 3 Sample my_plan.txt file output: COMP100 Mo 10.00 HIST300 Th 14.00 ECON201 We 12.00 PHYS102 Tu 14.00 ETHC113 Tu 08.00 def main(): #YOUR CODE HERE pass def initialize_dict(): #YOUR CODE HERE pass def add_course (courses, my plan): #YOUR CODE HERE pass def remove_course(courses,my_plan): #YOUR CODE HERE pass def write_plan_to_txt(my_plan): #YOUR CODE HERE pass #HELPER METHODS def get_course_info(courses, new course): #It takes the general courselist and a course name #Returns the day and time info of the course in a string #You don't have to implement this method pass def check_conflict(courses, my plannew.course): #It takes the general courselist, user's plan and a course name #Returns in there is a conflict, returns the conflicting course name #If no conflicts, returns empty string #You don't have to implement this method pass def does_course_exist(courses, my_course): #It takes the general courselist and a course name #Returns True if that course exists in the general course list pass def do_i_have_this_course(my_plan,my.course): #It takes user's plan and a course name #Returns True if that course exists in the user's plan pass main() 1 In part (2) of the voluntary homework, you are supposed to find out if a specific file already exists or not. You can do this by making use of either the exists() or the isfile() function from the "os" built-in library. Assuming there is a file named file1.txt but no file named file2.txt, then the usage and results of these functions are as follows: import os print(os.path.exists('filel.txt')) print(os.path.exists('file2.txt')) print(os.path.isfile('filel.txt')) print (os.path.isfile('file2.txt')) Console window output: True False True False

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Neo4j Data Modeling

Authors: Steve Hoberman ,David Fauth

1st Edition

1634621913, 978-1634621915

More Books

Students also viewed these Databases questions

Question

The number of new ideas that emerge

Answered: 1 week ago

Question

Evaluate three pros and three cons of e-prescribing

Answered: 1 week ago