def run_tests(): """Run tests to show workings of Car and Taxi classes.""" test_bus = Car("Test Bus", 200) test_bus.drive(30) print("fuel =", test_bus.fuel) print("odo =", test_bus.odometer) test_bus.drive(60) print("fuel =", test_bus.fuel) print("odo = ", test_bus.odometer) print(test_bus) # Drive a bus print("Enter driving distance:") distance = int(input(">> ")) while distance > 0: distance_travelled = test_bus.drive(distance) print("{} has travelled {} km.".format(test_bus, distance_travelled)) print("Enter driving distance (km):") distance = int(input(">> ")) test_taxi = Taxi("Test Taxi", 100) print(test_taxi) test_taxi.drive(30) print(test_taxi, test_taxi.get_fare()) test_taxi.start_fare() test_taxi.drive(60) print(test_taxi, test_taxi.get_fare()) fancy_taxi = Taxi("Test Fancy Taxi", 100, 2) print(fancy_taxi) fancy_taxi.drive(30) print(fancy_taxi, fancy_taxi.get_fare())
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(): print("Let's drive!") name = input("Enter your car name: ") car_simulator = Car(name, 100) print(car_simulator) menu_string = "Menu:\nd) drive\nr) refuel\nq) quit\nEnter your choice: " menu_input = input(menu_string).upper() while menu_input != "Q": if menu_input == "D": distance = int(input("How many kms do you wish to drive? ")) if distance > car_simulator.fuel: print("{} drove {}km and ran out of fuel.".format( car_simulator.name, car_simulator.fuel)) else: print("{} drove {}km".format(car_simulator.name, distance)) car_simulator.drive(distance) elif menu_input == "R": refuel = int( input( "How many units of fuel do you want to add to the car? ")) car_simulator.add_fuel(refuel) print("{} units of fuel added to {}".format( refuel, car_simulator.name)) else: print("Invalid choice: ") print(car_simulator) menu_input = input(menu_string).upper() print("Goodbye {} driver.".format(car_simulator.name))
def main(): """Demo test code to show how to use car class.""" my_car = Car("Holden", 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)) # Create a new Car object called "limo" that is initialised with 100 units of fuel. limo = Car("Limo", 100) # print(limo.fuel) # Add 20 more units of fuel to this new car object using the add method. limo.fuel += 20 # Print the amount of fuel in the car. print(limo.fuel) # Attempt to drive the car 115km using the drive method. limo.drive(115) # Print the car's odometer reading. print(limo.odometer) print(limo)
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)) ''' # MOD 1) limo = Car("limo", 100) print("Your {} has {}km worth of fuel".format(limo.name, limo.fuel)) # MOD 2) limo.add_fuel(20) print( "You fill up with 20km of fuel, Your {} has {}km worth of fuel".format( limo.name, limo.fuel)) # MOD 3) print("limo fuel =", limo.fuel) # MOD 4) limo.drive(115) print("Your {} drives {}km".format(limo.name, limo.odometer)) # MOD 5) print("limo odometer =", limo.odometer) # MOD 6) print(limo)
def main(): """Demo test code to show how to use car class.""" limo = Car(100,"My Limo") limo.add_fuel(20) limo.drive(115) print(limo.odometer) print(limo)
def run_tests(): 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) 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(): print("Let's drive!") car_name = input('Enter your car name: ') user_car = Car(car_name, 100) print_menu(user_car) user_choice = input('Enter your choice: ').upper() while user_choice != 'Q': if user_choice == 'D': if user_car.fuel == 0: print("The car has no fuel left. Please select 'r' to refuel.") else: drive_distance = get_int_above_zero('How many units of fuel do you want to add to the car? ') user_car.drive(drive_distance) print_menu(user_car) user_choice = input('Enter your choice: ').upper() elif user_choice == 'R': refuel_amount = get_int_above_zero('How many units of fuel do you want to add to the car? ') user_car.add_fuel(refuel_amount) print_menu(user_car) user_choice = input('Enter your choice: ').upper() else: print('Invalid choice!\n') print_menu(user_car) user_choice = input('Enter your choice: ').upper() print("Goodbye {}'s driver".format(user_car.name))
def main(): """Demo test code to show how to use car class.""" my_car = Car("First 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)) # 1 limo = Car(100) # 2 limo.add_fuel(20) # 3 print("fuel =", limo.fuel) # 4 limo.drive(115) # 5 print("odo =", limo.odometer) # 6 - added to car.py print(limo) # 7 limo.name = "Limo" limo.fuel = 120 # 8 print(limo)
def main(): 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(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 - {}".format(limo.fuel)) limo.drive(115) print("Limo odometer - {}".format(limo.odometer)) print(my_car) print(limo)""" limo = Car("Limo", 100) limo.add_fuel(20) print("Limo fuel - {}".format(limo.fuel)) limo.drive(115) print("Limo odometer - {}".format(limo.odometer)) print(my_car) print(limo)
def main2(): """The work done for the preactical""" 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.""" limo = Car("Limo", 100) limo.add_fuel(20) print("fuel =", 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(120) # my_car.drive(30) my_limo = Car(100) my_limo.add_fuel(20) my_limo.drive(115) # print("fuel =", my_limo.fuel) my_limo.name = "Fancy Limo" print(my_limo)
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))
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))
def main(): """Demo test code to show how to use car class.""" """First Car Instance""" my_car = Car("car", 180) my_car.drive(30) print(my_car) limo = Car("Limo", 100) limo.add_fuel(20) limo.drive(115) print(limo)
def main(): """Demo test code to show how to use car class.""" limo = Car(100) 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(): """Test code to used Car class""" my_car = Car(180, "car") my_car.drive(30) limo = Car(100, "Limo") limo.add_fuel(20) # print("fuel =", my_car.fuel) print("odo =", my_car.odometer) print(my_car) print("limo fuel =", limo.fuel) limo.drive(115) print("limo odometer =", limo.odometer) print(limo)
def main(): 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 {self.fuel}, {self.odometer}".format(self=my_car)) limo = Car("Limo", 100) limo.add_fuel(20) print('Limo {}'.format(limo.fuel)) limo.drive(115) print('Limo odo: {}'.format(limo.odometer)) print('Limo {self.fuel}, {self.odometer}'.format(self=limo))
def main(): """Demo test code to show how to use car class.""" my_car = Car("Ferrari", 42, 177) my_car.drive(30) limo = Car("Limo", 100) limo.add_fuel(20) limo.drive(115) print("{self.name}, fuel={self.fuel}, odometer={self.odometer}".format( self=my_car)) print(limo.fuel) print(limo.odometer) print("Car {}, {}".format(my_car.fuel, my_car.odometer)) print("Car {self.fuel}, {self.odometer}".format(self=my_car))
def main(): """Demo test code to show how to use car class.""" my_car = Car("my car", 180) my_car.drive(30) print(my_car) limo = Car("limo", 100) limo.add_fuel(20) limo.drive(115) print(limo.odometer) print(limo)
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) """Limo car test""" 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(180, "My Car") my_car.drive(30) limo = Car(100, "Limo") limo.add_fuel(20) limo.drive(115) print("Limo fuel =", limo.fuel) print("Limo odo=", limo.odometer) print("fuel =", my_car.fuel) print("odo =", my_car.odometer) print(my_car) print(limo) print("{} {}, {}".format(my_car.name, my_car.fuel, my_car.odometer)) print("Car {self.fuel}, {self.odometer}".format(self=my_car))
def main(): my_car = Car("My car", 180) my_car.drive(30) print("fuel =", my_car.fuel) print("odometer =", 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(): """Demo test code to show how to use car class.""" my_car = Car('Used Car', 100) 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('{} Fuel: {}'.format(limo.name, limo.fuel)) limo.drive(115) print('{} Odometer: {}'.format(limo.name, limo.odometer))
def main(): 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 {car.fuel}, {car.odometer}".format(car=my_car)) limo = Car("Limo", 100) limo.add_fuel(20) print(limo.fuel) limo.drive(115) print(limo.odometer)
def main(): """Simulate a car drive using Car class.""" print("Let's drive!") name = input("Enter your car name: ") car = Car(name, 100) print(car) print(MENU) choice = input("Enter your choice: ") while choice.lower() != 'q': if choice.lower() == 'd': distance = get_valid_distance() maximum_distance = car.drive(distance) if maximum_distance < distance: print("The car drove {}km and ran out of fuel\n".format( maximum_distance)) else: print("The car drove {}km\n".format(distance)) elif choice.lower() == 'r': refuel = get_valid_refuel() car.add_fuel(refuel) print("Added {} units of fuel.\n".format(refuel)) else: print("Invalid choice\n") print(car) print(MENU) choice = input("Enter your choice: ") print("\nGood Bye {}'s driver.".format(car.name))
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("There is {} units of fuel in the limo".format(limo.fuel)) limo.drive(115) print("The cars odometer reading is: {}".format(limo.odometer))
def main(): """Demo test code to show how to use car class.""" my_car = Car(180, "Test Car") my_car.drive(30) print("fuel =", my_car.fuel) print("odo =", my_car.odometer) print(my_car) print() limo = Car(100, "Limo") limo.add_fuel(20) limo.drive(115) print("fuel =", limo.fuel) print("odo =", limo.odometer) print(limo)
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("{} {}, {}".format(my_car.name, my_car.fuel, my_car.odometer)) print("{} {self.fuel}, {self.odometer}".format(my_car.name, self=my_car)) my_car = Car("Limo", 100) my_car.add_fuel(20) print("{} has {} units of fuel".format(my_car.name, my_car.fuel)) my_car.drive(115) print("{}'s odometer is {}".format(my_car.name, my_car.odometer))