def main(): car = Car("My car", 180) car.drive(30) print("fuel =", car.fuel) print("odo =", car.odometer) print(car) print("Car {}, {}".format(car.fuel, car.odometer)) print("Car {self.fuel}, {self.odometer}".format(self=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("literals", 319) my_car.drive(277) print("fuel =", my_car.fuel) print("odo =", my_car.odometer) print(my_car) print("Car {}, {}".format(my_car.fuel, my_car.odometer)) print("{self.name}, {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("Ferrari", 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("MINI Cooper", 100) 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(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(100, "Limo") limo.add_fuel(20) print(f"fuel = {limo.fuel}") limo.drive(115) print(f"odo = {limo.odometer}") print(limo)
def run_tests(): """Run the tests on the functions.""" # assert test with no message - used to see if the function works properly assert repeat_string("Python", 1) == "Python" # the test below should fail assert repeat_string("hi", 2) == "hi hi" # assert test with custom message, # used to see if Car's init method sets the odometer correctly # this should pass (no output) test_car = Car() assert test_car.odometer == 0, "Car does not set odometer correctly" # Note that Car's __init__ function sets the fuel in one of two ways: # using the value passed in or the default test_car = Car(fuel=10) assert test_car.fuel == 10 test_car = Car() assert test_car.fuel == 0
def main(): car = [] # List of car objects 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(name, 100) print(car) print(MENU) choice = input("Enter your choice: ").lower() while choice != "q": if choice == "d": distance_to_drive = int( input("How many km do you wish to drive? ")) while distance_to_drive < 0: print("Distance must be >= 0") distance_to_drive = int( input("How many km do you wish to drive? ")) distance_driven = car.drive(distance_to_drive) print("The car drove {}km".format(distance_driven), end="") if car.fuel == 0: print(" and ran out of fuel", end="") print(".") elif choice == "r": fuel_to_add = int( input( "How many units of fuel do you want to add to the car? ")) while fuel_to_add < 0: print("Fuel amount must be >= 0") fuel_to_add = int( input( "How many units of fuel do you want to add to the car? " )) car.add_fuel(fuel_to_add) print("Added {} units 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.name))
def main(): limo = Car("Limo", 100) print(limo.car) limo.add_fuel(20) print(limo.fuel) limo.drive(115) print(limo.odometer)
def run_tests(): """Run the tests on the functions.""" # assert test with no message - used to see if the function works properly assert repeat_string("Python", 1) == "Python" # the test below should fail assert repeat_string("hi", 2) == "hi hi" # TODO: 1. fix the repeat_string function above so that it passes the failing test # Hint: "-".join(["yo", "yo"] -> "yo-yo" # assert test with custom message, # used to see if Car's init method sets the odometer correctly # this should pass (no output) test_car = Car() assert test_car.odometer == 0, "Car does not set odometer correctly" # TODO: 2. write assert statements to show if Car sets the fuel correctly # Note that Car's __init__ function sets the fuel in one of two ways: # using the value passed in or the default # You should test both of these test_car = Car(fuel=10) assert test_car.fuel == 10, "Car does not fuel correctly" test_car = Car() assert test_car.fuel == 0, "Car does not fuel correctly"