Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #Tasks
- #1. Two objects: Car and Gas Station
- #2. List several attributes for each object
- #3. List at least one method that the object employs
- #4. Create Python pseudocode for each object, don't forget the __init__() function.
- #5. Post your pseudo code to this task discussion.
- # Extra Credit: Have one of the objects return information that is utilized by the other object.
- class Car:
- """Typical personal transport vehicle in use since the beginning of the
- 20th century"""
- def __init__(self, make, seats, fuel_type, power):
- "initialisation of an instance of the car class"
- self.make = make
- self.seats = seats
- self.fuel_type = fuel_type
- self.power = power #in kWh
- self.fuel_level = 0.0 #initially the fuel tank is empty (in liters)
- def calculate_fuel(self, new_fuel):
- "Calculate the fuel in the car's tank"
- self.fuel_level += float(new_fuel)
- print ("It has now %d liters of fuel.") % (self.fuel_level)
- class GasStation:
- "A place where one can fill up the fuel tank of one's car."
- def __init__(self, hydrogen_price):
- "Creates an instance of the GasStation class"
- self.h2_price = float(hydrogen_price)
- def get_fuel(self, Car, fuel):
- """Gets fuel for the Car and calculates price and new fuel level,
- by passing the added fuel to the Car.calculate_fuel method """
- price = float(fuel) * self.h2_price
- print "The %s has taken %d liters. Total cost is: %d." % (Car.make, fuel, price)
- Car.calculate_fuel(fuel)
- mycar = Car('Riversimple', 4, 'hydrogen', 60)
- hydrogenstation = GasStation(2.45)
- hydrogenstation.get_fuel(mycar, 8.5)
- hydrogenstation.get_fuel(mycar, 4)
- dirtycar = Car('Ford', 7, 'gasoline', 150)
- gasstation = GasStation(1.8)
- gasstation.get_fuel(dirtycar, 50)
- exit()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement