Example #1
0
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)

    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? "))

    new_taxi = Taxi("Prius 1", 100)
    print(new_taxi)
    new_taxi.drive(25)
    print(new_taxi, new_taxi.get_fare())
    new_taxi.start_fare()
    new_taxi.drive(40)
    print(new_taxi, new_taxi.get_fare())

    new_silver_service_taxi = SilverServiceTaxi("Limo", 100, 2)
    print(new_silver_service_taxi, new_silver_service_taxi.get_fare())
    new_silver_service_taxi.drive(10)
    print(new_silver_service_taxi, new_silver_service_taxi.get_fare())
Example #2
0
def run_tests():
    """Run tests to show workings of Car and Taxi classes."""
    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())
def tests():
    car = Car("Datsun", 180)
    car.drive(30)
    print("fuel =", car.fuel)
    print("odo =", car.odometer)
    car.drive(55)
    print("fuel =", car.fuel)
    print("odo = ", car.odometer)
    print(car)

    distance = int(input("Drive how far? "))
    while distance > 0:
        travel = car.drive(distance)
        print("{} travelled {}".format(str(car), travel))
        distance = int(input("Drive how far? "))

    taxis = Taxi("Prius 1", 100)
    taxis.drive(25)
    print(taxis)
    print(taxis, taxis.get_fare())
    taxis.start_fare()
    taxis.drive(40)
    print(taxis, taxis.get_fare())

    silver_service_taxi = SilverServiceTaxi("Limo", 100, 2)
    print(silver_service_taxi, silver_service_taxi.get_fare())
    silver_service_taxi.drive(10)
    print(silver_service_taxi, silver_service_taxi.get_fare())
 def drive(self, distance):
     """Similar to parent Car, but pass in reliability attribute."""
     if random.uniform(1, 100) < self.reliability:
         distance_driven = Car.drive(self, distance)
     else:
         distance_driven = 0
     return distance_driven
Example #5
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))

    limo = Car("Limo", 100)
    limo.add_fuel(20)
    print("fuel =", limo.fuel)
    limo.drive(115)
    print("odo =", limo.odometer)
    print(str(limo))
Example #6
0
def run_tests():
    """Test the Car and Taxi class to show they're working."""
    # Test Car Class
    ferrari = Car("Ferrari", 1000)
    ferrari.drive(333)
    print("Ferrari fuel:{}".format(ferrari.fuel))
    print("Ferrari odometer:{}".format(ferrari.odometer))
    ferrari.drive(200)
    print("Ferrari fuel after driving another 200km:{}".format(ferrari.fuel))
    print("Ferrari odo after driving another 200km:{}".format(ferrari.odometer))
    print(ferrari)

    # Test Taxi Class
    truck = Taxi("Hyundai", 500)
    truck.start_fare()
    truck.drive(333)
    print("Current fare distance of truck is{}".format(truck.current_fare_distance))
    print("Fare of Taxi Hyundai after driving 333 is {}".format(truck.get_fare()))

    # Test SilverServiceClass
    truck = SilverServiceTaxi("Hyundai", 500, 1)
    truck.start_fare()
    truck.drive(333)
    print("Fare of SilverServiceTaxi Hyundai after driving 333 is {}".format(truck.get_fare()))
 def drive(self, distance):
     start = random.randint(0, 100)
     if start < self.reliability:
         Car.drive(self, distance)
     else:
         print("Car didn't start")