Menu

[Solved]-Question 4 110 Marks Totall Complete Code Incomplete Code Defines New Class Vehicle Object Q37248002

Python
Question 4 110 marks totall-Complete the Code The incomplete code below defines a new class of Vehicle objects. Parts A, B anQuestion 4 110 marks totall-Complete the Code The incomplete code below defines a new class of Vehicle objects. Parts A, B and C ask you to complete the sections of the code in the boxes according to the methods” docstrings. Part D asks you to write what would be printed by the preceding code. class Vehicle: def init (self, speed, maxSpeed, colour): sel f . speed- peed # in km/h self.maxspeed-maxSpeed in km/h self.colour colour def accelerate (self, x) Increases the Vehicle object’s speed by x. Note that the Vehicle cannot have a speed higher than its maxSpeed attribute. def brake (self, x): self.speed self.speed x if (self.speed <0): 0 self, speed def race (self, other): Returns the Vehicle object self or other, whichever has a higher apeed. In the case of a tie, returns the self object B (3 marks) def st (self) Returns the Vehicle in the form: <colour> vehicle travelling at <speed> km/h >>>print (Vehicle(0,100, “red”) red vehicle traveling at 0 ㎞/h marks red car-Vehicle (60, 200, “red”) blue car Vehicle(80. 160. “blue”) red car.accelerate (10) blue car.brake (5) print (“The winner of the race is”, red car.race (blue car)) Show transcribed image text Question 4 110 marks totall-Complete the Code The incomplete code below defines a new class of Vehicle objects. Parts A, B and C ask you to complete the sections of the code in the boxes according to the methods” docstrings. Part D asks you to write what would be printed by the preceding code. class Vehicle: def init (self, speed, maxSpeed, colour): sel f . speed- peed # in km/h self.maxspeed-maxSpeed in km/h self.colour colour def accelerate (self, x) Increases the Vehicle object’s speed by x. Note that the Vehicle cannot have a speed higher than its maxSpeed attribute. def brake (self, x): self.speed self.speed x if (self.speed >>print (Vehicle(0,100, “red”) red vehicle traveling at 0 ㎞/h marks red car-Vehicle (60, 200, “red”) blue car Vehicle(80. 160. “blue”) red car.accelerate (10) blue car.brake (5) print (“The winner of the race is”, red car.race (blue car))

Expert Answer


Answer to Question 4 110 marks totall-Complete the Code The incomplete code below defines a new class of Vehicle objects. Parts A,… . . .

OR


Leave a Reply

Your email address will not be published. Required fields are marked *