help python plz.
Posted: Thu May 26, 2022 9:08 am
help python plz.
Figure Q1 shows the Module class which is described in Table Q1. Module _validStartCharacterOfCode: ['B', 'E', 'T', 'S'] _code: str _level: int _init_(self, code, level) code(self):str level(self):int level(self, newLevel) change LevelBy(self, change ByLevel) get DifferenceInLevels(self, Module): int addValidStartCharacter(cls, startCharacter) removeValidStartCharacter(cls, startCharacter) _str_(self): str Figure 01
The Module class has the following attributes: The Module class has the following methods: A code for a module starts with either the letter B, E, I or S, e.g., S123. The code uniquely identifies a module The valid start letters of a module code are recorded in a list: ['B', 'E', 'T', 'S']. A level that a module is taught at is a whole number from 1 to 5, inclusive of 1 and 5. _init__(self, code, level) initialises a new module with the values code and level. If the code does not start with one of the letters in the list ['B', 'E', 'I', 'S'], the first letter in the list replaces the start character in the code. code(self):str returns the code of a module. level(self):int returns the level of a module. level(self, newLevel) sets the level of a module to the value in new Level. changeLevelBy(self, changeByLevel) changes the level of a module by the value in changeByLevel. If the value of changeByLevel is positive, the level is increased by the value. The level after the change is adjusted to 5 if the resulting level is greater than 5. O ● If the value of changeByLevel is negative, the level is decreased by the value. The level after the change is adjusted to 1 if the resulting level is less than 1. getDifferenceInLevels(self, module) returns the difference between the level of a module and the level of the parameter module. If the parameter module has a higher level, the method returns a negative difference. If the parameter module has a lower level, the method returns a positive difference add ValidStartCharacter(cls, startCharacter) adds the new character value in startCharacter to the list of letters that a module code can start with. remove ValidStartCharacter(cls, startCharacter) removes the character value in startCharacter from the list of letters that a module code can start with. _str__(self) returns a string representation of a module. An example string is shown here: Code: S123 Level: 3 Table Q1
(a) (b) (c) Identify the attributes and methods of the Module class: (i) List the attributes, and categorise each attribute as either class or instance. (ii) List the methods and categorise each method as class or instance. Identify methods as initializer, getter and setter methods, where applicable. Write a Python class definition for the Module class. Write Python statements to perform the following actions: (i) Create TWO (2) Module objects, and reference them by the variables m1 and m2 respectively. Use the data shown here, to create the Module objects: Module code level ml S123 3 m2 B231 2 Change the level of m1 by 2 and set the level of m2 to 1. Get the difference in levels between m1 and m2, and display the difference. Add the letter T to the list of valid start letters of a module code. (ii) (iii) (iv)
Figure Q1 shows the Module class which is described in Table Q1. Module _validStartCharacterOfCode: ['B', 'E', 'T', 'S'] _code: str _level: int _init_(self, code, level) code(self):str level(self):int level(self, newLevel) change LevelBy(self, change ByLevel) get DifferenceInLevels(self, Module): int addValidStartCharacter(cls, startCharacter) removeValidStartCharacter(cls, startCharacter) _str_(self): str Figure 01
The Module class has the following attributes: The Module class has the following methods: A code for a module starts with either the letter B, E, I or S, e.g., S123. The code uniquely identifies a module The valid start letters of a module code are recorded in a list: ['B', 'E', 'T', 'S']. A level that a module is taught at is a whole number from 1 to 5, inclusive of 1 and 5. _init__(self, code, level) initialises a new module with the values code and level. If the code does not start with one of the letters in the list ['B', 'E', 'I', 'S'], the first letter in the list replaces the start character in the code. code(self):str returns the code of a module. level(self):int returns the level of a module. level(self, newLevel) sets the level of a module to the value in new Level. changeLevelBy(self, changeByLevel) changes the level of a module by the value in changeByLevel. If the value of changeByLevel is positive, the level is increased by the value. The level after the change is adjusted to 5 if the resulting level is greater than 5. O ● If the value of changeByLevel is negative, the level is decreased by the value. The level after the change is adjusted to 1 if the resulting level is less than 1. getDifferenceInLevels(self, module) returns the difference between the level of a module and the level of the parameter module. If the parameter module has a higher level, the method returns a negative difference. If the parameter module has a lower level, the method returns a positive difference add ValidStartCharacter(cls, startCharacter) adds the new character value in startCharacter to the list of letters that a module code can start with. remove ValidStartCharacter(cls, startCharacter) removes the character value in startCharacter from the list of letters that a module code can start with. _str__(self) returns a string representation of a module. An example string is shown here: Code: S123 Level: 3 Table Q1
(a) (b) (c) Identify the attributes and methods of the Module class: (i) List the attributes, and categorise each attribute as either class or instance. (ii) List the methods and categorise each method as class or instance. Identify methods as initializer, getter and setter methods, where applicable. Write a Python class definition for the Module class. Write Python statements to perform the following actions: (i) Create TWO (2) Module objects, and reference them by the variables m1 and m2 respectively. Use the data shown here, to create the Module objects: Module code level ml S123 3 m2 B231 2 Change the level of m1 by 2 and set the level of m2 to 1. Get the difference in levels between m1 and m2, and display the difference. Add the letter T to the list of valid start letters of a module code. (ii) (iii) (iv)