python programming
3 years ago
15
Pythonquiz.pdf
Pythonquiz.pdf
Q1:
Write a class named Car that has the following data attributes:
__year_model: (for the car's year model) __make: (for the make of the car) __speed: (for the car's current speed)
In addition, the class should have the following methods:
__init__ method that accepts the car’s year model and make as arguments.
These values should be assigned to the object’s year_model and make data attributes. It should also assign 0 to the __speed data attribute. accelerate: The accelerate method should add 5 to the speed data attribute when it is called. brake: The brake method should subtract 5 from the speed data attribute each time it is called. get_speed: The get_speed method should return the current speed
Q2:
Write a class named Person that has the following instance attributes:
name : name of the person
In addition, the Person class should have the following methods:
__init__ method that accepts a name as the argument and assigns it to the instance's name attributes.
Write a class named Student that inherits from the Person class. The Student class has a new
instance attribute:
score : the score of the student, the default value is 60
In addition, the Student class should have the following methods:
__init__ method that accepts a name and a score as arguments. These values should be
assigned to the instance's name and score attributes.
set_score : an instance method that accepts an argument and assigns it to the instance attribute
score .
get_score : an instance method that returns the instance attribute score .
Write a class named School that has the following class attribute:
students : a list
In addition, the School class should have the following class method:
add_student : a class method that appends a Student instance to the class attribute students .
example:
>>> s1 = Student("Tom", 80)
>>> s2 = Student("Jerry")
>>> School.add_student(s1)
>>> School.add_student(s2)
>>> print(School.students[0].score)
>>> print(School.students[1].score)
80 60
>>>
- Q1:
- Q2:
- Revision
- Book Synopsis
- I have 5 discussions needs to answer
- Behavioral and Social/Cognitive Approaches to Forming Habits
- A wonderful donation by james butcher argumentive essay
- Instructional Plan Design Analysis
- Manageriak Accounting
- Construct Mind Map for Tonsillitis and Hypertension
- presentation
- Need a conclusion only