Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- print ("Welcome! This program is going to help you calculate the self-cost of your car in the format of price per kilometre.")
- forename = input("Let's get to know each other! My name is PythonProgram1, what's yours? ")
- print ("Nice to meet you " + forename + ", let's get started!")
- print ("")
- print ("Easy stuff first, let's calculate the amortization of the vehicle.")
- def sanitised_input(prompt, type_=None, min_=None, max_=None, range_=None):
- if min_ is not None and max_ is not None and max_ < min_:
- raise ValueError("min_ must be less than or equal to max_.")
- while True:
- ui = input(prompt)
- if type_ is not None:
- try:
- ui = type_(ui)
- except ValueError:
- print("Input type must be {0}.".format(type_.__name__))
- continue
- if max_ is not None and ui > max_:
- print("Input must be less than or equal to {0}.".format(max_))
- elif min_ is not None and ui < min_:
- print("Input must be greater than or equal to {0}.".format(min_))
- elif range_ is not None and ui not in range_:
- if isinstance(range_, range):
- template = "Input must be between {0.start} and {0.stop}."
- print(template.format(range_))
- else:
- template = "Input must be {0}."
- if len(range_) == 1:
- print(template.format(*range_))
- else:
- print(template.format(" or ".join((", ".join(map(str,
- range_[:-1])),
- str(range_[-1])))))
- else:
- return ui
- currentvalue = sanitised_input("Please enter the current value of your vehicle: ", float, 0)
- period = sanitised_input("Please enter the usage time period in years: ", int, 1, 25)
- remainingvalue = sanitised_input("Please enter the remaining value of your vehicle: ", float, 0, currentvalue)
- ylostval = (currentvalue-remainingvalue)/period
- mlostval = ((currentvalue-remainingvalue)/period)/12
- print ("")
- print ("That means our car is losing value of " + format(ylostval, '.2f') + " per year.")
- print ("That's " + format(mlostval, '.2f') + " per month.")
- print ("")
- print ("Let's move on to some more in depth stuff.")
- fuelconsumption = sanitised_input ("Please enter your car's fuel consumption (l/100km): ", float, 0)
- fuelprice = sanitised_input("Please enter fuel price per litre: ", float, 0)
- insurance = sanitised_input("Please enter the yearly insurance fee: ", float, 0)
- inspectioncost = sanitised_input("Please enter the cost of technical inspection: ", float, 0)
- inspectionint = sanitised_input("Please enter the interval of the technical inspection in years: ", int, 0, 5)
- tiresprice = sanitised_input("Please enter the cost of tires: ", float, 0)
- tiresdurability = sanitised_input("Please enter the durability of the tires in kilometres: ", int, 0)
- lease = sanitised_input("Please enter the monthly lease payment (0 if none): ", float, 0)
- maintenance = sanitised_input("Please enter the average cost of maintenance and repairs in a year: ", float, 0)
- mileage = sanitised_input("Please enter the amount of kilometres you drive in a year: ", int, 0)
- print ("")
- print ("Thank you for baring with me " + forename + ". Now the calculations:")
- costfuel = (fuelconsumption*fuelprice)/100
- costtires = tiresprice/tiresdurability
- costmaintenance = maintenance/mileage
- costinspection = inspectioncost/inspectionint
- costlease = lease*12
- costinsurance = insurance
- costyearly = insurance+costinspection+costlease
- costmonthly = costyearly/12
- costvariable = costfuel+costtires+costmaintenance
- costfinal = costvariable+(costyearly/mileage)
- costtotal = (costvariable*mileage)+costyearly
- print ("Your yearly fixed costs are " + format(costyearly, '.2f') + ".")
- print ("That equals to " + format(costmonthly, '.2f') + " per month.")
- print ("Your variable costs are " + format(costvariable, '.2f') + " per kilometre.")
- print ("What influences your self-price per kilometre the most is the amount of kilometres you drive.")
- print ("At your yearly mileage of " + str(mileage) + " km, your final price per kilometre comes down to:")
- print (format(costfinal, '.2f'))
- print ("And your total costs per year are " + format(costtotal, '.2f') + ".")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement