Using Inheritance to Create a Derived Class in Motorcycle.py MyMotorcycleClassPr. Vehicle py + >- Terminal Python 1 # This program uses the programmer-defined Motorcycle class. Traceback (most recent call last): File "/root/sandbox/MyMotorcycleClassProgram.py", line 11, in motorcycleOne - Motorcycle(90.0) TypeError: Motorcycle._init._() takes 1 positional argument but 2 were given 2 3 # Do NOT edit this file. Write your code in Motorcycle.py, 4 # then open this file and click "Run Code". 1. Open the file named Motorcycle.py. 2. Create the Motorcycle class by deriving it from the Vehicle class. 5 Call the parent class init() method inside the Motorcycle 6 from Motorcycle import Motorcycle class's init()-- method. 8 motorcycleOne = Motorcycle(90.0, 65.0, True) 9 motorcycleTwo = Motorcycle(85.0, 60.0, False) 3. In the Motorcycle class, create an attribute named sidecar. 10 11 motorcycle0ne.accelerate(30.0) 12 motorcycleTwo.accelerate(20.0) 13 14 print("The current speed of motorcycleOne is " + str(motorcycleOne. speed)) 15 print("The current speed of motorcycleTwo is + str(motorcycleTwo.speed)) 16 17 if motorcycleOne.get_sidecar(): 18 19 else: 4. Write a public set method to set the value for sidecar. 5. Write a public get method to retrieve the value of sidecar. 6. Write a public accelerate method. This method overrides the accelerate method inherited from the Vehicle class. Change the message in the accelerate method so the following is displayed when the Motorcycle tries to accelerate beyond its maximum print("This motorcycle has a sidecar") speed: "This motorcycle cannot go that fast". 20 print("This motorcycle does not have a sidecar") 21 22 if motorcycleTwo.get_sidecar(): 7. Open the file named MyMotorcycleClassProgram.py. 8. In the MyMotorcycleClassProgram, there are two Motorcycle 23 24 else: 25 print("This motorcycle has a sidecar") objects named motorcycleOne and motorcycleTwo. print("This motorcycle does not have a sidecar") 9. Set the sidecar value of motorcycleOne to True and the sidecar 26 value of motorcycleTwo to False. 10. Set motorcycleOne 's maximum speed to 90 and motorcycleTwo 's maximum speed to 85. 11. Set motorcycleOne 's current speed to 65 and motorcycleTwo 's current speed to 60. 12. Accelerate motorcycleOne by 30 mph, and accelerate motorcycleTwo by 20 mph. 13. Print the current speed of motorcycleOne and motorcycleTwo. 14. Determine if motorcycleOne and motorcycleTwo have sidecars. If yes, display the following: "This motorcycle has a sidecar". If not, display the following: "This motorcycle does not have a sidecar".
Using Inheritance to Create a Derived Class in Motorcycle.py MyMotorcycleClassPr. Vehicle py + >- Terminal Python 1 # This program uses the programmer-defined Motorcycle class. Traceback (most recent call last): File "/root/sandbox/MyMotorcycleClassProgram.py", line 11, in motorcycleOne - Motorcycle(90.0) TypeError: Motorcycle._init._() takes 1 positional argument but 2 were given 2 3 # Do NOT edit this file. Write your code in Motorcycle.py, 4 # then open this file and click "Run Code". 1. Open the file named Motorcycle.py. 2. Create the Motorcycle class by deriving it from the Vehicle class. 5 Call the parent class init() method inside the Motorcycle 6 from Motorcycle import Motorcycle class's init()-- method. 8 motorcycleOne = Motorcycle(90.0, 65.0, True) 9 motorcycleTwo = Motorcycle(85.0, 60.0, False) 3. In the Motorcycle class, create an attribute named sidecar. 10 11 motorcycle0ne.accelerate(30.0) 12 motorcycleTwo.accelerate(20.0) 13 14 print("The current speed of motorcycleOne is " + str(motorcycleOne. speed)) 15 print("The current speed of motorcycleTwo is + str(motorcycleTwo.speed)) 16 17 if motorcycleOne.get_sidecar(): 18 19 else: 4. Write a public set method to set the value for sidecar. 5. Write a public get method to retrieve the value of sidecar. 6. Write a public accelerate method. This method overrides the accelerate method inherited from the Vehicle class. Change the message in the accelerate method so the following is displayed when the Motorcycle tries to accelerate beyond its maximum print("This motorcycle has a sidecar") speed: "This motorcycle cannot go that fast". 20 print("This motorcycle does not have a sidecar") 21 22 if motorcycleTwo.get_sidecar(): 7. Open the file named MyMotorcycleClassProgram.py. 8. In the MyMotorcycleClassProgram, there are two Motorcycle 23 24 else: 25 print("This motorcycle has a sidecar") objects named motorcycleOne and motorcycleTwo. print("This motorcycle does not have a sidecar") 9. Set the sidecar value of motorcycleOne to True and the sidecar 26 value of motorcycleTwo to False. 10. Set motorcycleOne 's maximum speed to 90 and motorcycleTwo 's maximum speed to 85. 11. Set motorcycleOne 's current speed to 65 and motorcycleTwo 's current speed to 60. 12. Accelerate motorcycleOne by 30 mph, and accelerate motorcycleTwo by 20 mph. 13. Print the current speed of motorcycleOne and motorcycleTwo. 14. Determine if motorcycleOne and motorcycleTwo have sidecars. If yes, display the following: "This motorcycle has a sidecar". If not, display the following: "This motorcycle does not have a sidecar".
Computer Networking: A Top-Down Approach (7th Edition)
7th Edition
ISBN:9780133594140
Author:James Kurose, Keith Ross
Publisher:James Kurose, Keith Ross
Chapter1: Computer Networks And The Internet
Section: Chapter Questions
Problem R1RQ: What is the difference between a host and an end system? List several different types of end...
Related questions
Question
error on python code: File "/root/sandbox/MyMotorcycleClassProgram.py", line 11, in <module>
motorcycleOne = Motorcycle(90.0)
TypeError: Motorcycle.__init__() takes 1 positional argument but 2 were given
from Vehicle import Vehicle
# Write the Motorcycle class here
class Motorcycle(Vehicle):
def__init__(self):
Vehicle.__init__(self)
self._sidecar = sidecar
defset_sidecar(self,sC):
self._sidecar = sidecar
defget_sidecar(self):
returnself._sidecar
defaccelerate(self,mph):
ifself._speed + mph >self._max_speed:
self._speed =self._speed + mph
else:
print("This motorcycle cannot go that fast.")
Expert Solution
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution!
Trending now
This is a popular solution!
Step by step
Solved in 2 steps
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Computer Networking: A Top-Down Approach (7th Edi…
Computer Engineering
ISBN:
9780133594140
Author:
James Kurose, Keith Ross
Publisher:
PEARSON
Computer Organization and Design MIPS Edition, Fi…
Computer Engineering
ISBN:
9780124077263
Author:
David A. Patterson, John L. Hennessy
Publisher:
Elsevier Science
Network+ Guide to Networks (MindTap Course List)
Computer Engineering
ISBN:
9781337569330
Author:
Jill West, Tamara Dean, Jean Andrews
Publisher:
Cengage Learning
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY