def run_tests(): """Run tests to show workings of Car and Taxi classes.""" bus = Car("Datsun", 180) bus.drive(30) print("fuel =", bus.fuel) print("odo =", bus.odometer) bus.drive(55) print("fuel =", bus.fuel) print("odo = ", bus.odometer) print(bus) # drive bus (input/loop is oblivious to fuel) distance = int(input("Drive how far? ")) while distance > 0: travelled = bus.drive(distance) print("{} travelled {}".format(str(bus), travelled)) distance = int(input("Drive how far? ")) t = Taxi("Prius 1", 100) print(t) t.drive(25) print(t, t.get_fare()) t.start_fare() t.drive(40) print(t, t.get_fare()) sst = SilverServiceTaxi("Limo", 100, 2) print(sst, sst.get_fare()) sst.drive(10) print(sst, sst.get_fare())
def main(): """Demo test code to show how to use car class.""" my_car = Car("car", 180) my_car.drive(30) print("fuel =", my_car.fuel) print("odo =", my_car.odometer) print(my_car) print("Car {}, {}".format(my_car.fuel, my_car.odometer)) print("Car {self.fuel}, {self.odometer}".format(self=my_car))
def main(): # my_car = Car (180) # my_car.drive(30) limo=Car(100, "My Limousine") limo.add_fuel(20) print("fuel = ", limo.fuel) limo.drive(115) print("odo = ", limo.odometer) print(limo) print("Car {}, {}".format(limo.fuel, limo.odometer)) print("Car {self.fuel}, {self.odometer}".format(self=limo))
def main(): """Demo test code to show how to use car class.""" # my_car = Car(180) (fuel) is passed into my_car argument # my_car.drive(30) (distance) is passed into my_car.drive argument limo = Car(100, "Limo") #initialise limo & (fuel) is passed into limo argument limo.add_fuel(20) #added 20 more to fuel print("fuel =", limo.fuel) limo.drive(115) #(distance) is passed into limo.drive argument print("odo =", limo.odometer) print(limo) print("Car {}, {}".format(limo.fuel, limo.odometer)) print("Car {self.fuel}, {self.odometer}".format(self=limo))
def main(): my_car = Car("lancer", 180) my_car.drive(30) print("fuel =", my_car.fuel) print("odo =", my_car.odometer) print(my_car) print("Car {}, {}".format(my_car.fuel, my_car.odometer)) print("Car {self.fuel}, {self.odometer}".format(self=my_car)) limo = Car("limo", 100) limo.add_fuel(20) print(limo.fuel) limo.drive(115) print(limo.odometer) print(limo)
def main(): """Demo test code to show how to use car class.""" my_car = Car("My car", 180) my_car.drive(30) print("fuel =", my_car.fuel) print("odo =", my_car.odometer) print(my_car) print("Car {}, {}".format(my_car.fuel, my_car.odometer)) print("Car {self.fuel}, {self.odometer}".format(self=my_car)) limo = Car("Limo", 100) limo.add_fuel(20) print(limo.fuel) limo.drive(115) print(limo.odometer)
def main(): """Car simulator program, demonstrating use of Car class.""" print("Let's drive!") name = input("Enter your car name: ") # create a Car instance with initial fuel of 100 and user-provided name car = Car(type, 100) print(car) print(MENU) choice = input("Enter your choice: ").lower() while choice != "q": if choice == "d": distance_to_drive = int(input("How far do you want to go? ")) while distance_to_drive < 0: print("Distance must be >= 0") distance_to_drive = int(input("How far do you want to go? ")) distance_driven = car.drive(distance_to_drive) print("The car has driven {}km".format(distance_driven), end="") if car.fuel == 0: print(" out of fuel", end="") print(".") elif choice == "r": fuel_to_add = int(input("How much fule are you putting in? ")) while fuel_to_add < 0: print("Fuel must be >= 0") fuel_to_add = int(input("How much fule are you putting in? ")) car.add_fuel(fuel_to_add) print("Added {} L of fuel.".format(fuel_to_add)) else: print("Invalid choice") print() print(car) print(MENU) choice = input("Enter your choice: ").lower() print("\nGood bye {}'s driver.".format(car.type))
def main(): """Demo test code to show how to use car class.""" my_car = Car(180) my_car.drive(30) print("fuel =", my_car.fuel) print("odo =", my_car.odometer) print(my_car) print("Car {}, {}".format(my_car.fuel, my_car.odometer)) print("Car {self.fuel}, {self.odometer}".format(self=my_car)) limo = Car("limo", 100) limo.add_fuel(20) print("Limo has {} units of fuel".format(limo.fuel)) limo.drive(115) print("Limo has travelled a total distance of {}km".format(limo.odometer)) print(limo) bus = Car("bus", 200) print(bus)
"""CP1404/CP5632 Practical - Client code to use the Car class.""" # Note that the import has a folder (module) in it. from prac_6.car import Car def main(): """Demo test code to show how to use car class.""" my_car = Car("car", 180) my_car.drive(30) print("fuel =", my_car.fuel) print("odo =", my_car.odometer) print(my_car) print("Car {}, {}".format(my_car.fuel, my_car.odometer)) print("Car {self.fuel}, {self.odometer}".format(self=my_car)) main() limo = Car("limo", 100) limo.add_fuel(20) print("fuel =", limo.fuel) limo.drive(115) print("odo =", limo.odometer) print(limo)