Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

need python code for this from course import Course class Schedule: Contains courses. def __init__(self, courses: [Course] = []) -> None: Creates a

need python code for this

from course import Course

class Schedule:

""" Contains courses.

"""

def __init__(self, courses: [Course] = []) -> None:

"""Creates a schedule containing courses.

Parameters:

- self: mandatory reference to this object

- courses: list of Course objects.

Returns:

none

"""

pass

def __str__(self) -> str:

"""Returns the string to be printed when this object is passed to print().

The representation contains each course separated by two newline

characters. The courses are ordered by the start time of their

classes. The last line indicates the total number of credit hours.

Parameters:

- self: mandatory reference to this object

Returns:

A string representation of this object.

"""

pass

def add_course(self, course: Course) -> bool:

"""Returns the success status of adding course to the schedule.

course is successfully added if it does not conflict with an existing

course. Otherwise, adding fails.

Parameters:

- self: mandatory reference to this object

- course: course to be added

Returns:

True if adding course succeeds, False otherwise.

"""

pass

def remove_course(self, course: str) -> bool:

"""Returns the success status of removing course from the schedule.

course is represented by its title. It is successfully removed if the

schedule contains a course of the same title. Otherwise, removing fails.

Parameters:

- self: mandatory reference to this object

- course: title of course to be removed

Returns:

True if removing course succeeds, False otherwise.

"""

pass

the course class is:

import datetime

class Course:

""" Holds information on a course and its assignments.

"""

def __init__(self, title: str, hours: int, teacher: str, time: datetime.datetime) -> None:

"""Creates a course with the given information.

Parameters:

- self: mandatory reference to this object

- title: name of the course

- hours: total credit hours of the course

- teacher: name of the instructor

- time: date and time of the start of the first class

Returns:

none

"""

self.title = title

self.hrs = hours

self.teach = teacher

self.t = time

self.assignments = []

self.total_weightage = 0

pass

def __str__(self) -> str:

"""Returns the string to be printed when this object is passed to str().

The representation contains the course's title, hours, instructor name,

and class time separated by newline.

Parameters:

- self: mandatory reference to this object

Returns:

A string representation of this object.

"""

return 'course title' + self.title + ' hours' + self.hrs + ' instructor name' + self.teach + ' class time' + self.t

pass

def add_assignment(self, assignment: (str, int)) -> bool:

"""Returns the success status of adding assignment to the list of this course's

assignments.

assignment is represented by its title and weightage, e.g. ('HW1',

10). It can be added to the list of assignments if adding the weightage

does not cause the total weightage to exceed 100 and the list does not

already contain an assignment with the same title. Otherwise it cannot

and adding fails.

Parameters:

- self: mandatory reference to this object

- assignment: a tuple containing the assignment name and weightage

Returns:

True if adding assignment succeeds, False otherwise.

"""

assignment_name = ""

weightage = 0

assignment = assignment_name,weightage

if weightage + self.total_weightage > 100:

return False

for assign in self.assignments:

if assign[0] == assignment_name:

return False

self.assignments.append(assignment)

self.total_weightage += weightage

return True

pass

def remove_assignment(self, assignment: str) -> bool:

"""Returns the success status of removing assignment from the list of this

course's assignments.

assignment is represented by its title, e.g. 'HW1'. It can be removed

from the list of assignments if it already exists in the list. Otherwise

it cannot and removing fails.

Parameters:

- self: mandatory reference to this object

- assignment: the title of the assignment

Returns:

True if removing assignment succeeds, False otherwise.

"""

for i in range (len(self.assignments)):

if self.assignments[i]['title'] == assignment:

del self.assignments[i]

return True

return False

pass

def print_assignments(self) -> None:

"""Prints the assignments contained in the list of this course's assignments.

Each assignment is printed on a new line in increasing order of

weightage. Assignments with the same weightage are printed in any

order. Each assignment is printed as its name and weightage separated by

a tab character.

Parameters:

- self: mandatory reference to this object

Returns:

none

"""

self.assignments.sort(key = lambda x: x['weightage'])

for assignment in self.assignments:

print(assignment['title'] + '\t' + str(assignment['weightage']))

pass

def is_complete(self) -> None:

"""Returns whether the course is complete, i.e. the total weightage of the

stored assignments is 100.

Parameters:

- self: mandatory reference to this object

Returns:

True if the course is complete, False otherwise.

"""

total_weightage = 0

for assignment in self.assignments:

total_weightage += assignment['weightage']

return total_weightage == 100

pass

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

The World Wide Web And Databases International Workshop Webdb 98 Valencia Spain March 27 28 1998 Selected Papers Lncs 1590

Authors: Paolo Atzeni ,Alberto Mendelzon ,Giansalvatore Mecca

1st Edition

3540658904, 978-3540658900

More Books

Students also viewed these Databases questions

Question

10-9 How have social technologies changed e-commerce?

Answered: 1 week ago