Advertisement
Guest User

Untitled

a guest
Apr 27th, 2017
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.35 KB | None | 0 0
  1. print ("Welcome! This program is going to help you calculate the self-cost of your car in the format of price per kilometre.")
  2. forename = input("Let's get to know each other! My name is PythonProgram1, what's yours? ")
  3. print ("Nice to meet you " + forename + ", let's get started!")
  4. print ("")
  5. print ("Easy stuff first, let's calculate the amortization of the vehicle.")
  6.  
  7. def sanitised_input(prompt, type_=None, min_=None, max_=None, range_=None):
  8. if min_ is not None and max_ is not None and max_ < min_:
  9. raise ValueError("min_ must be less than or equal to max_.")
  10. while True:
  11. ui = input(prompt)
  12. if type_ is not None:
  13. try:
  14. ui = type_(ui)
  15. except ValueError:
  16. print("Input type must be {0}.".format(type_.__name__))
  17. continue
  18. if max_ is not None and ui > max_:
  19. print("Input must be less than or equal to {0}.".format(max_))
  20. elif min_ is not None and ui < min_:
  21. print("Input must be greater than or equal to {0}.".format(min_))
  22. elif range_ is not None and ui not in range_:
  23. if isinstance(range_, range):
  24. template = "Input must be between {0.start} and {0.stop}."
  25. print(template.format(range_))
  26. else:
  27. template = "Input must be {0}."
  28. if len(range_) == 1:
  29. print(template.format(*range_))
  30. else:
  31. print(template.format(" or ".join((", ".join(map(str,
  32. range_[:-1])),
  33. str(range_[-1])))))
  34. else:
  35. return ui
  36.  
  37. currentvalue = sanitised_input("Please enter the current value of your vehicle: ", float, 0)
  38. period = sanitised_input("Please enter the usage time period in years: ", int, 1, 25)
  39. remainingvalue = sanitised_input("Please enter the remaining value of your vehicle: ", float, 0, currentvalue)
  40.  
  41. ylostval = (currentvalue-remainingvalue)/period
  42. mlostval = ((currentvalue-remainingvalue)/period)/12
  43.  
  44. print ("")
  45. print ("That means our car is losing value of " + format(ylostval, '.2f') + " per year.")
  46. print ("That's " + format(mlostval, '.2f') + " per month.")
  47. print ("")
  48. print ("Let's move on to some more in depth stuff.")
  49. fuelconsumption = sanitised_input ("Please enter your car's fuel consumption (l/100km): ", float, 0)
  50. fuelprice = sanitised_input("Please enter fuel price per litre: ", float, 0)
  51. insurance = sanitised_input("Please enter the yearly insurance fee: ", float, 0)
  52. inspectioncost = sanitised_input("Please enter the cost of technical inspection: ", float, 0)
  53. inspectionint = sanitised_input("Please enter the interval of the technical inspection in years: ", int, 0, 5)
  54. tiresprice = sanitised_input("Please enter the cost of tires: ", float, 0)
  55. tiresdurability = sanitised_input("Please enter the durability of the tires in kilometres: ", int, 0)
  56. lease = sanitised_input("Please enter the monthly lease payment (0 if none): ", float, 0)
  57. maintenance = sanitised_input("Please enter the average cost of maintenance and repairs in a year: ", float, 0)
  58. mileage = sanitised_input("Please enter the amount of kilometres you drive in a year: ", int, 0)
  59.  
  60. print ("")
  61. print ("Thank you for baring with me " + forename + ". Now the calculations:")
  62.  
  63. costfuel = (fuelconsumption*fuelprice)/100
  64. costtires = tiresprice/tiresdurability
  65. costmaintenance = maintenance/mileage
  66.  
  67. costinspection = inspectioncost/inspectionint
  68. costlease = lease*12
  69. costinsurance = insurance
  70. costyearly = insurance+costinspection+costlease
  71. costmonthly = costyearly/12
  72.  
  73. costvariable = costfuel+costtires+costmaintenance
  74.  
  75. costfinal = costvariable+(costyearly/mileage)
  76. costtotal = (costvariable*mileage)+costyearly
  77.  
  78. print ("Your yearly fixed costs are " + format(costyearly, '.2f') + ".")
  79. print ("That equals to " + format(costmonthly, '.2f') + " per month.")
  80. print ("Your variable costs are " + format(costvariable, '.2f') + " per kilometre.")
  81. print ("What influences your self-price per kilometre the most is the amount of kilometres you drive.")
  82. print ("At your yearly mileage of " + str(mileage) + " km, your final price per kilometre comes down to:")
  83. print (format(costfinal, '.2f'))
  84. print ("And your total costs per year are " + format(costtotal, '.2f') + ".")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement