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)

    # 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())
示例#2
0
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("{} {}, {}".format(my_car.car_name, my_car.fuel, my_car.odometer))
    print("{self.car_name} {self.fuel}, {self.odometer}".format(self=my_car))
示例#3
0
def main():
    """Demo test code to show how to use car class."""
    limo = Car("limo", 100)
    limo.add_fuel(20)
    limo.drive(115)
    print(limo)
    print("fuel =", limo.fuel)

    print("{} {}, {}".format(limo.name, limo.fuel, limo.odometer))
    print("{self.name} {self.fuel}, {self.odometer}".format(self=limo))
def main():
    my_car = Car(180)
    my_car.drive(30)
    print("fuel =", my_car.fuel)
    print("odo =", my_car.odometer)
    print(my_car)
    limo = Car(100, "limo")
    limo.add_fuel(20)
    print(limo.fuel)
    limo.drive(115)
    print(limo.odometer)
示例#5
0
def main():
    """Demo test code to show how to use car class."""
    my_car = Car("WRX", 60)
    my_car.drive(30)
    limo = Car("Limo", 100)
    limo.add_fuel(20)
    limo.drive(115)
    # print("fuel =", my_car.fuel)
    # print("odo =", my_car.odometer)
    print(my_car)
    print(limo.fuel)
示例#6
0
def main():
    """Demo test code to show how to use car class."""
    limo = Car(100)
    my_car = Car(180)
    limo.drive(115)
    limo.add_fuel(20)
    print("fuel =", limo.fuel)
    print("odo =", limo.odometer)
    print(limo)

    print("Car {}, {}".format(my_car.fuel, my_car.odometer))
    print("Car {self.fuel}, {self.odometer}".format(self=my_car))
示例#7
0
def main():
    my_car = Car(180)
    my_car.drive(30)
    my_car.name = "Car"
    print("Car Fuel =", my_car.fuel)
    print("Car Odo =", my_car.odometer)
    print(my_car)

    limo = Car(100)
    limo.add_fuel(20)
    print("Limo Fuel:", limo.fuel)
    limo.drive(115)
    print("Limo Odo", limo.odometer)
示例#8
0
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 {self.fuel}, {self.odometer}".format(self=my_car), "\n")

    limo = Car(100)
    limo.add_fuel(20)
    print("fuel =", limo.fuel)
    limo.drive(115)
    print("odo =", limo.odometer)
示例#9
0
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))

    limo = Car("Limo", 100)
    limo.add_fuel(20)
    print("Limo fuel =", limo.fuel)
    limo.drive(115)
    print("Limo odometer =", limo.odometer)
示例#10
0
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))
    # Exercise 1
    limo = Car("Limo", 100)
    limo.add_fuel(20)
    print("fuel = {}".format(limo.fuel))
    limo.drive(115)
    print("odo = {}".format(limo.odometer))
    print(limo)
示例#11
0
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))

    my_limo = Limo(100)
    my_limo.add_fuel(20)
    print("fuel =", my_limo.add_fuel)
    Limo.drive(my_limo, 115)
    print("odo =".format(my_limo.drive), my_limo.odometer)
def main():
    """Main."""
    print("Let's Drive")
    car_name = input("Enter your car name: ").title()
    player_car = Car(car_name, 100)
    print(player_car)

    print(MENU)
    menu_selection = input("Enter your choice: ").lower()
    while menu_selection != QUIT:
        if menu_selection == DRIVE:
            distance = get_positive_number(
                "How many km do you wish to drive? ")
            traveled = player_car.drive(distance)
            if traveled < distance:
                warning_string = " and ran out of fuel."
            else:
                warning_string = "."
            print("The car drove {}km{}".format(traveled, warning_string))
        elif menu_selection == REFUEL:
            units_fuel = get_positive_number(
                "How many units of fuel do you want to add to the car? ")
            player_car.add_fuel(units_fuel)
            print("Added {} units of fuel.".format(units_fuel))
        else:
            print("Invalid menu choice, try again.")
        print(player_car)
        print(MENU)
        menu_selection = input(">>>").lower()
    print("Good bye {}'s driver.".format(player_car.name))
示例#13
0
def main():
    bus = Car(180, 'Bus')
    bus.drive(30)
    print("fuel =", bus.fuel)
    print("odo =", bus.odometer)
    print(bus)
    print(str(bus))

    print("{}, {}".format(bus.fuel, bus.odometer))
    print("{self.fuel}, {self.odometer}".format(self=bus))

    limo = Car(100, 'Limo')
    limo.add_fuel(20)
    print("fuel =", limo.fuel)
    limo.drive(115)
    print("odo =", limo.odometer)

    print(limo)
示例#14
0
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(limo.fuel)
    limo.drive(115)
    print(limo.odometer)
    print(str(limo))
示例#15
0
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("fuel =", limo.fuel)
    limo.drive(115)
    print("odo =", limo.odometer)
    print("{self.name}, fuel={self.fuel}, odometer={self.odometer}".format(
        self=limo))
    print(limo)
示例#16
0
def main():
    """Demo guitar_gibson code to show how to use car class."""

    my_car = Car(180, "Car")
    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.name} {self.fuel}, {self.odometer}".format(self=my_car))

    limo = Car(100, "Limo")
    limo.add_fuel(20)
    print("fuel =", limo.fuel)
    limo.drive(115)
    print("odo =", limo.odometer)
    print(limo)
示例#17
0
def main():
    print(("Car fuel and odometer").upper())
    current_fuel_car = int(input("Current fuel car: >>> "))
    my_car = Car("My car",
                 current_fuel_car)  #  Pascal shows that this is class "Car"
    current_odometer_car = int(input("Current odometer car: >>> "))
    my_car.drive(current_odometer_car)  #  drive is part of the Car class
    print("Car Fuel: {} ".format(my_car.fuel))
    print("Car Odometer: {} ".format(my_car.odometer))
    print("{}".format(my_car))
    print()
    print("-" * 20)
    print()
    print(("Limo fuel and odometer").upper())
    current_fuel_limo = int(input("Current fuel limo: >>> "))
    limo = Car("Limo", current_fuel_limo)
    limo.add_fuel(int(input("Additional fuel: >>> ")))
    current_distance_driven = int(input("Distance driven: >>> "))
    limo.odometer += current_distance_driven
    print("{}".format(limo))
示例#18
0
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(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))
示例#19
0
def main():
    """build a car simulator using car class."""
    print("Let's drive!")
    car_name = ""
    while car_name == "":
        car_name = input("Enter your car name: ")
    car_in_play = Car(car_name, 100)
    menu_selection = ""
    while menu_selection.upper() != QUIT_SELECTED:
        print(car_in_play)
        print(MENU)
        menu_selection = input("Enter your choice: ")
        if menu_selection not in MENU_OPTIONS:
            print("Invalid choice\n")
        elif menu_selection.upper() == DRIVE_SELECTED:
            valid_distance = False
            while not valid_distance:
                try:
                    drive_distance = float(input("How many km do you wish to drive? "))
                    if drive_distance >= 0:
                        print("The car drove {:.0f}km{}.\n".format(car_in_play.drive(drive_distance)
                            , " and ran out of fuel" if car_in_play.fuel == 0 else ""))
                        valid_distance = True
                    else:
                        print("Distance must be >= 0")
                except:
                    print("Invalid distance")
        elif menu_selection.upper() == REFUEL_SELECTED:
            valid_fuel = False
            while not valid_fuel:
                try:
                    fuel_added = float(input("How many units of fuel do you want to add to the car? "))
                    if fuel_added >= 0:
                        print("Added {:.0f} units of fuel.\n".format(car_in_play.add_fuel(fuel_added)))
                        valid_fuel = True
                    else:
                        print("Fuel amount must be >= 0")
                except:
                    print("Invalid fuel amount")
    print("\nGood bye {}'s driver.".format(car_in_play.model_name))
def main():
    print("Lets Drive!")
    car_name = input("Enter your car name: ")
    the_bomb = Car(100, car_name)
    print(str(the_bomb))
    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 is_invalid(distance_to_drive):
                print("Distance must be >= 0")
                distance_to_drive = int(
                    input("How many km do you wish to drive? "))
            distance_driven = the_bomb.drive(distance_to_drive)
            print("The car drove {}km".format(distance_driven), end="")
            if the_bomb.fuel == 0:
                print(" and ran out of fuel. ")
        elif choice == "r":
            refuel_amount = int(
                input(
                    "How many units of fuel do you want to add to the car? "))
            while is_invalid(refuel_amount):
                print("Fuel amount must be > = 0")
                refuel_amount = int(
                    input(
                        "How many units of fuel do you want to add to the car? "
                    ))
            the_bomb.add_fuel(refuel_amount)
            print("Added {} units of fuel.".format(refuel_amount))
        else:
            print("Invalid Choice")
        print(str(the_bomb))
        print(MENU)
        choice = input("Enter your choice: ").lower()
    print("Goodbye {}'s driver.".format(car_name))