34.1k views
0 votes
Write the implementation of a class Cse20 Topic that represents a topic in the cse20 class. The class should implement the init function, getters, and override the str and add functions.

1 Answer

2 votes

Answer:

class Cse20_topic:

def __init__(self, title, length):

self.title = title

self.length = length

def get_length(self):

return self.length

def get_title(self):

return self.title

def get_length_in_days(self):

return self.length*7

def __str__(self):

return f'Title: {self.title}, length: {self.length}'

def __add__(self, other):

return self.length+other.length

Step-by-step explanation:

The python program above defines the class Cse20 which is used to create a topic ( instance of the Cse20 object). The getter methods like the get_lenght, get_title and get_length_in_days return the length of a topic object, the title of the topic and the topic length in days respectively while the __str__ and __add__ methods overrides the string object and addition of topic length respectively.

User Kamilg
by
5.6k points