« All Events
5 PM – Python OOP – Bill
May 10, 2022 @ 5:00 pm - 6:00 pm
Today We:
- Reviewed HW and attributes of a class that have a default value
- Added a gas_tank attribute that also has a default value
- Made a fill_gas_tank method
- Added a drive method that lets the car use up gas
- Created a new empty list variable called garage
- Filled the garage list with a bunch of car instances
- Looped through each car in the garage and printed them out
- Learned how to only print out a car that meets specific criteria like printing out only toyota cars
Your HW:
- Open your restaurant class hw
- Do Page 167 – TRY IT YOURSELF
- Download and install latest Python from: https://www.python.org/downloads/
- Download and install latest Community Edition Pycharm: https://www.jetbrains.com/pycharm/download/
- Optional Practice On the Car Class:
- Make a max_gas_tank atribute that needs to be in the __init__ function
- Make it so the gas_tank default atribute cannot be greater than the max_gas_tank attribute in the fill_gas_tank method
- Create another new atribute, miles_per_gallon, that also needs to be in the __init__ function
- Make it so in the drive method, instead of dividing the distance by 50 for the gas_consumption variable, divide the distance by the miles_per_gallon attribute.
- Make sure that anytime you created a new car to specify the new max_gas_tank attribute and the miles_per_gallon attribute.