Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Test Taxi File: taxi_test.py Create a separate file to try out your first taxi. We don't usually write client code in class files, but rather

Test Taxi

File: taxi_test.py

Create a separate file to try out your first taxi. We don't usually write client code in class files, but rather we use separate files.

Write lines of code for each of the following (hint: use the methods available in the Taxi class):

Create a new taxi object, my_taxi, with name "Prius 1", 100 units of fuel and price of $1.23

Drive the taxi 40 km

Print the taxi's details and the current fare

Restart the meter (start a new fare) and then drive the car 100 km

Print the details and the current fare

python

""" CP1404/CP5632 Practical Car class """ from prac_09.car import Car class Taxi(Car): """Specialised version of a Car that includes fare costs.""" def __init__(self, name, fuel, price_per_km): """Initialise a Taxi instance, based on parent class Car.""" super().__init__(name, fuel) self.price_per_km = price_per_km self.current_fare_distance = 0 def __str__(self): """Return a string like a Car but with current fare distance.""" return f"{super().__str__()}, {self.current_fare_distance}km on current fare, ${self.price_per_km:.2f}/km" def get_fare(self): """Return the price for the taxi trip.""" return self.price_per_km * self.current_fare_distance def start_fare(self): """Begin a new fare.""" self.current_fare_distance = 0 def drive(self, distance): """Drive like parent Car but calculate fare distance as well.""" distance_driven = super().drive(distance) self.current_fare_distance += distance_driven return distance_driven

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

What is the effect of word war second?

Answered: 1 week ago