예제 #1
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.add_fuel(20)

    print("limo fuel after top up ={}".format(limo.fuel))

    limo.drive(115)

    print("limo's odometer now = {}".format(limo.odometer))
    print("limo fuel after driving ={}".format(limo.fuel))

    print(my_car)
    print(limo)
예제 #2
0
파일: used_cars.py 프로젝트: Leylun/Sandbox
def main():
    """Demo test code to show how to use car class."""
    limo = Car(100, "Limo")
    limo.add_fuel(20)
    print("fuel =", limo.fuel)
    limo.drive(115)
    print("odo =", limo.odometer)
    print(limo)
예제 #3
0
def main():
    my_car = Car(180, 'Sedan')
    my_car.drive(30)
    print("fuel =", my_car.fuel)
    print("odo =", my_car.odometer)
    print(my_car)

    print('** Limo **')
    limo = Car(100, 'Limo')
    limo.add_fuel(20)
    print('fuel =', limo.fuel)
    limo.drive(115)
    print('odo =', limo.odometer)
    print(limo)
예제 #4
0
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 {}, {}".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)
예제 #5
0
def main():
    """Demo test code to show how to use car class."""

    # 1. limo = Car(100)
    limo = Car("Limo", 100)  # 7. updated with name
    # 2.
    limo.add_fuel(20)
    # 3.
    print("Limo fuel =", limo.fuel)
    # 4.
    limo.drive(115)
    # 5.
    print("Limo odo =", limo.odometer)
    # 6.
    print(limo)
예제 #6
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(limo.fuel)
    limo.drive(115)
    print(limo.odometer)
예제 #7
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, fuel = {self.fuel}, odometer = {self.odometer}".format(
        self=my_car))

    limo = Car(100)
    limo.add_fuel(20)
    print("Limo's fuel = ", limo.fuel)
    limo.drive(115)
    print("limo's odometer reading: ", limo.odometer)
예제 #8
0
def main():
    print("Let's drive!")
    car_name = str(input("Enter your car name"))
    my_car = Car(car_name)
    print("{}, fuel = {}, odo = {}".format(my_car.name, my_car.fuel,
                                           my_car.odometer))
    menu_choice = insert_menu()
    while menu_choice.lower() == "d" or menu_choice.lower() == "r":

        if menu_choice.lower() == "d":
            while True:
                try:
                    distance = float(input("how many km you want to drive? "))
                    while distance < 0:
                        print("the distance must be >=0")
                        distance = float(
                            input("how many km you want to drive? "))

                    break
                except ValueError:
                    print("Invalid Input Value")
            my_car.drive(distance)
            print("{}, fuel = {}, odo = {}".format(my_car.name, my_car.fuel,
                                                   my_car.odometer))
            menu_choice = insert_menu()
        else:
            while True:
                try:
                    amount = float(
                        input(
                            "How many units of fuel do you want to add to the car? "
                        ))
                    while amount < 0:
                        print("Fuel amount must be >= 0")
                        amount = float(
                            input(
                                "How many units of fuel do you want to add to the car? "
                            ))

                    break
                except ValueError:
                    print("Invalid Input Value")
            my_car.add_fuel(amount)
            print("{}, fuel = {}, odo = {}".format(my_car.name, my_car.fuel,
                                                   my_car.odometer))
            menu_choice = insert_menu()
예제 #9
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("limo", 100)
    limo.add_fuel(20)
    limo.drive(115)

    print(limo.fuel)
    print(limo.odometer)
    print(limo.specs())
예제 #10
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))
예제 #11
0
def main():
    print("Let's drive!")
    name = input("Enter your car 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("Good bye {}'s driver.".format(car.name))
예제 #12
0
def main():
    """Demo test code to show how to use car class."""
    my_car = Car(180, 'My 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("Car {self.fuel}, {self.odometer}".format(self=my_car))

    #1. create new car object called limo and set the fuel to 100
    limo = Car(100,'limo')
    #2. add 20 more units of fuel to this new car object using the add method
    limo.add_fuel(20)
    #3. print the amount of fuel in the limo car
    print('limo fuel = ',limo.fuel)
    #4. attempt to drvie 115km
    limo.drive(115)
    #5. print the car's odometer reading
    print('limo odometer = ',limo.odometer)
    print(limo)
            while distance_in_km < 0:
                distance_in_km = int(
                    input('How many km do you wish to drive? '))

                if distance_in_km < 0:
                    print('Distance must be >= 0')

            actual_distance = car.drive(distance_in_km)
            if car.fuel == 0:
                print('The car drive {}km and run out of fuel'.format(
                    actual_distance))
            else:
                print('The car drive {}km'.format(actual_distance))
            distance_in_km = -1
        elif user_choice == 'r':

            while units_of_fuel < 0:
                units_of_fuel = int(
                    input(
                        'How many units of fuel do you want to add to the card?'
                    ))

                if units_of_fuel < 0:
                    print('Fuel amount must be >= 0')

            car.add_fuel(units_of_fuel)
            print('Added {} units of fuel'.format(units_of_fuel))
            units_of_fuel = -1

print("Good bye {}'s driver.".format(name))