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))
Esempio n. 2
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)
Esempio n. 4
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)
Esempio n. 5
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))
Esempio n. 6
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)
Esempio n. 7
0
def add_fuel(Car):
    amount_of_added_fuel = input(
        "How many units of fuel do you want to add to the car? ")
    valid_input = check_if_integer(amount_of_added_fuel)
    while valid_input is False:
        print("Fuel amount must be >= 0")
        amount_of_added_fuel = input(
            "How many units of fuel do you want to add to the car? ")
        valid_input = check_if_integer(amount_of_added_fuel)

    Car.add_fuel(amount_of_added_fuel)
    print("Added {} units of fuel".format(amount_of_added_fuel))
    print(Car)
Esempio n. 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)
Esempio n. 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)
Esempio n. 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)
Esempio n. 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))

    limo = Car(100, "Limo")
    limo.add_fuel(20)
    print(limo.fuel)
    limo.drive(115)
    print(limo.odometer)
    print(str(limo))
Esempio n. 12
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)
Esempio n. 13
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)
Esempio n. 14
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)
Esempio n. 15
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))
Esempio n. 16
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))
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))
Esempio n. 18
0
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 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)
    test_car.add_fuel(10)
    assert test_car.fuel == 20
    print(test_car.fuel)
Esempio n. 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))