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...
icon
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.")

 

Using Inheritance to Create a Derived Class in
Motorcycle.py
MyMotorcycleClassPr.
Vehicle.py
>_ Terminal
1 # This program uses the programmer-defined Motorcycle class.
Python
Traceback (most recent call last):
File "/root/sandbox/MyMotorcycleClassProgram.py", line 11,
in <module>
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.
Motorcycle(90.0)
motorcycleOne
TypeError: Motorcycle._init_-() takes 1 positional argument
but 2 were given
2. Create the Motorcycle class by deriving it from the Vehicle class.
Call the parent class --init()-- method inside the Motorcycle
6 from Motorcycle import Motorcycle
7
class's -_init()-- method.
8 motorcycleOne
9 motorcycleTwo = Motorcycle(85.0, 60.0, False)
= Motorcycle(90.0, 65.0, True)
3. In the Motorcycle class, create an attribute named sidecar.
10
4. Write a public set method to set the value for sidecar.
11 motorcycleOne.accelerate(30.0)
12 motorcycle Two.accelerate(20.0)
5. Write a public get method to retrieve the value of sidecar.
13
14 print("The current speed of motorcycleOne is "
15 print ("The current speed of motorcycleTwo is "
+ str(motorcycleOne.speed))
+ str(motorcycleTwo.speed))
6. Write a public accelerate method. This method overrides the
accelerate method inherited from the Vehicle class. Change the
16
message in the accelerate method so the following is displayed
17 if motorcycleOne.get_sidecar():
when the Motorcycle tries to accelerate beyond its maximum
18
print("This motorcycle has a sidecar")
19 else:
speed: "This motorcycle cannot go that fast".
20
print("This motorcycle does not have a sidecar")
21
7. Open the file named MyMotorcycleClassProgram.py.
22 if motorcycleTwo.get_sidecar():
8. In the MyMotorcycleClassProgram, there are two Motorcycle
23
print("This motorcycle has a sidecar")
24 else:
objects named motorcycleOne and motorcycleTwo .
25
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".
15. Execute the program.
Transcribed Image Text:Using Inheritance to Create a Derived Class in Motorcycle.py MyMotorcycleClassPr. Vehicle.py >_ Terminal 1 # This program uses the programmer-defined Motorcycle class. Python Traceback (most recent call last): File "/root/sandbox/MyMotorcycleClassProgram.py", line 11, in <module> 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. Motorcycle(90.0) motorcycleOne TypeError: Motorcycle._init_-() takes 1 positional argument but 2 were given 2. Create the Motorcycle class by deriving it from the Vehicle class. Call the parent class --init()-- method inside the Motorcycle 6 from Motorcycle import Motorcycle 7 class's -_init()-- method. 8 motorcycleOne 9 motorcycleTwo = Motorcycle(85.0, 60.0, False) = Motorcycle(90.0, 65.0, True) 3. In the Motorcycle class, create an attribute named sidecar. 10 4. Write a public set method to set the value for sidecar. 11 motorcycleOne.accelerate(30.0) 12 motorcycle Two.accelerate(20.0) 5. Write a public get method to retrieve the value of sidecar. 13 14 print("The current speed of motorcycleOne is " 15 print ("The current speed of motorcycleTwo is " + str(motorcycleOne.speed)) + str(motorcycleTwo.speed)) 6. Write a public accelerate method. This method overrides the accelerate method inherited from the Vehicle class. Change the 16 message in the accelerate method so the following is displayed 17 if motorcycleOne.get_sidecar(): when the Motorcycle tries to accelerate beyond its maximum 18 print("This motorcycle has a sidecar") 19 else: speed: "This motorcycle cannot go that fast". 20 print("This motorcycle does not have a sidecar") 21 7. Open the file named MyMotorcycleClassProgram.py. 22 if motorcycleTwo.get_sidecar(): 8. In the MyMotorcycleClassProgram, there are two Motorcycle 23 print("This motorcycle has a sidecar") 24 else: objects named motorcycleOne and motorcycleTwo . 25 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". 15. Execute the program.
Using Inheritance to Create a Derived Class in
Motorcycle.py
Vehicle.py
+
+
MyMotorcycleClassPr.
>_ Terminal
1 from Vehicle import Vehicle
Python
Traceback (most recent call last):
File "/root/sandbox/MyMotorcycleClassProgram.py", line 11,
in <module>
2
3 # Write the Motorcycle class here
4 class Motorcycle(Vehicle):
def --init_-(self):
Vehicle._init__(self)
1. Open the file named Motorcycle.py.
motorcycleOne = Motorcycle(90.0)
TypeError: Motorcycle._init_-() takes 1 positional argument
but 2 were given
2. Create the Motorcycle class by deriving it from the Vehicle class.
Call the parent class --init()-- method inside the Motorcycle
7
self._sidecar = sidecar
class's _init()_- method.
8.
def set_sidecar(self, sC):
self._sidecar = sidecar
3. In the Motorcycle class, create an attribute named sidecar.
9.
10
4. Write a public set method to set the value for sidecar .
11
def get_sidecar(self):
return self._sidecar
12
5. Write a public get method to retrieve the value of sidecar.
13
14
6. Write a public accelerate method. This method overrides the
def accelerate(self, mph):
if self._speed + mph > self._max_speed:
self._speed = self._speed + mph
15
accelerate method inherited from the Vehicle class. Change the
16
message in the accelerate method so the following is displayed
17
18
else:
when the Motorcycle tries to accelerate beyond its maximum
19
print("This motorcycle cannot go that fast.")
speed: "This motorcycle cannot go that fast".
20
7. Open the file named MyMotorcycleClassProgram.py.
21
22
8. In the MyMotorcycleClassProgram, there are two Motorcycle
objects named motorcycleOne and motorcycleTwo .
9. Set the sidecar value of motorcycleOne to True and the sidecar
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".
15. Execute the program.
Transcribed Image Text:Using Inheritance to Create a Derived Class in Motorcycle.py Vehicle.py + + MyMotorcycleClassPr. >_ Terminal 1 from Vehicle import Vehicle Python Traceback (most recent call last): File "/root/sandbox/MyMotorcycleClassProgram.py", line 11, in <module> 2 3 # Write the Motorcycle class here 4 class Motorcycle(Vehicle): def --init_-(self): Vehicle._init__(self) 1. Open the file named Motorcycle.py. motorcycleOne = Motorcycle(90.0) TypeError: Motorcycle._init_-() takes 1 positional argument but 2 were given 2. Create the Motorcycle class by deriving it from the Vehicle class. Call the parent class --init()-- method inside the Motorcycle 7 self._sidecar = sidecar class's _init()_- method. 8. def set_sidecar(self, sC): self._sidecar = sidecar 3. In the Motorcycle class, create an attribute named sidecar. 9. 10 4. Write a public set method to set the value for sidecar . 11 def get_sidecar(self): return self._sidecar 12 5. Write a public get method to retrieve the value of sidecar. 13 14 6. Write a public accelerate method. This method overrides the def accelerate(self, mph): if self._speed + mph > self._max_speed: self._speed = self._speed + mph 15 accelerate method inherited from the Vehicle class. Change the 16 message in the accelerate method so the following is displayed 17 18 else: when the Motorcycle tries to accelerate beyond its maximum 19 print("This motorcycle cannot go that fast.") speed: "This motorcycle cannot go that fast". 20 7. Open the file named MyMotorcycleClassProgram.py. 21 22 8. In the MyMotorcycleClassProgram, there are two Motorcycle objects named motorcycleOne and motorcycleTwo . 9. Set the sidecar value of motorcycleOne to True and the sidecar 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". 15. Execute the program.
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 2 steps

Blurred answer
Similar questions
Recommended textbooks for you
Computer Networking: A Top-Down Approach (7th Edi…
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 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)
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
Concepts of Database Management
Computer Engineering
ISBN:
9781337093422
Author:
Joy L. Starks, Philip J. Pratt, Mary Z. Last
Publisher:
Cengage Learning
Prelude to Programming
Prelude to Programming
Computer Engineering
ISBN:
9780133750423
Author:
VENIT, Stewart
Publisher:
Pearson Education
Sc Business Data Communications and Networking, T…
Sc Business Data Communications and Networking, T…
Computer Engineering
ISBN:
9781119368830
Author:
FITZGERALD
Publisher:
WILEY