Example #1
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"

    assert repeat_string("bye", 4) == "bye bye bye bye"

    # 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, "Fuel not set correctly"

    test_car.fuel = 0
    assert test_car.fuel == 0, "Fuel not set correctly"

    print(sentence_format('hello'))
    print(sentence_format('It is an ex parrot.'))
Example #2
0
def main():
    """Simulate driving of car object"""

    print("Lets Drive!")
    car_name = get_name()
    my_car = Car(car_name, STARTING_FUEL)
    menu_choice = str(display_menu()).lower()

    while menu_choice != "q":

        if menu_choice == "d":
            print("How many km's do you wish to drive? ")
            drive_distance = get_int_entry()
            if my_car.fuel - drive_distance > 0:
                print("Your car drove {} kms ".format(drive_distance))
                my_car.odometer = my_car.odometer + drive_distance
                my_car.fuel = my_car.fuel - drive_distance
                print("Your car has travelled {} kms today".format(
                    my_car.odometer))

            else:
                print("Your car doesn't have enough fuel!")

            print(my_car)
            menu_choice = display_menu()

        elif menu_choice == "r":
            print("How many units of fuel do you wish to add to the car? ")
            amount_to_refuel = get_int_entry()

            print("Added {} units to the car".format(amount_to_refuel))
            print(my_car)
            menu_choice = display_menu()

        else:
            print("Invalid menu choice, please try again.")
            menu_choice = display_menu()

    print("Good by the {} 's driver! ".format(my_car.name))