5️⃣

13.5 Practice

Practice

This time, we've just got one big wrap-up problem

Car

A new car is said to devalue 20% in the first year. Assuming that this trend continues and that mileage divided by 100 is all you subtract from this adjusted price, make a class “car” that has at least the attributes year, original price (aka og_price), and mileage. Also, follow these guidelines.
  • When using str() on a car, it should return the year, original price, mileage, and adjusted price.
  • When adding, it should add the value (an int or float) to its mileage before adjusting the adjusted price
  • When multiplying, it should multiply the mileage by the value (and int or float) before adjusting the adjusted price
  • When subtracting or dividing, it should subtract the value from its mileage or divide its mileage by the value before adjusting the adjusted price
  • When checking gt, lt, ge, le, ne, and eq, it should compare the car's adjusted price with the other value
  • You should be able to compare cars (compare their adjusted prices) but not add, multiply, subtract, or divide cars by other cars
💡
If you need help with modeling the equation for the adjusted price, this may help: self.adjustedprice = self.ogprice * (0.8**(2021-self.year)) self.adjustedprice = round((self.adjustedprice, 2)) - self.mileage/100
 
⚖️
Copyright © 2021 Code 4 Tomorrow. All rights reserved. The code in this course is licensed under the MIT License. If you would like to use content from any of our courses, you must obtain our explicit written permission and provide credit. Please contact classes@code4tomorrow.org for inquiries.