Advertisement
Guest User

Untitled

a guest
Jul 21st, 2019
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.03 KB | None | 0 0
  1. #code starts here
  2. rentalCode = input("(B)udget, (D)aily, or (W)eekly rental?\n")
  3. #variables
  4. budget_charge = 40.00
  5. daily_charge = 60.00
  6. weekly_charge = 190.00
  7.  
  8.  
  9. # rentalCode is a variable whos values changes with user input, and also has a string attached
  10. if rentalCode == "B" or rentalCode == "D":
  11. rentalPeriod = input("Number of Days Rented:\n");
  12. elif rentalCode == "W":
  13. rentalPeriod = input("Number of Weeks Rented:\n")
  14.  
  15. if rentalCode == "B":
  16. baseCharge = int(rentalPeriod) * int(budget_charge)
  17. elif rentalCode == "D":
  18. baseCharge = int(rentalPeriod) * int(daily_charge)
  19. elif rentalCode == "W":
  20. baseCharge = int(rentalPeriod) * int(weekly_charge)
  21. print("%.2f" %baseCharge)
  22.  
  23. #Odometer readings are variables that have numerical values and strings attached
  24. odoStart = input("Starting Odometer Reading:\n")
  25. odoEnd = input("Ending Odometer Reading:\n")
  26. totalMiles = int(odoEnd) - int(odoStart)
  27.  
  28.  
  29.  
  30. #charge calcultor starts with IF Branch
  31. if rentalCode == "B":
  32. mileCharge = totalMiles * 0.25
  33. # ELIF is our secondary brach statement, revering to if the rental is based in Days
  34. elif rentalCode == "D":
  35. averageDayMiles = float(totalMiles)/float(rentalPeriod)
  36. if float(averageDayMiles) <= 100:
  37. extraMiles = 0
  38. # Our ELSE statement is the last Branch in a statment
  39. else:
  40. extraMiles = float(averageDayMiles) - 100
  41. mileCharge = (0.25 * float(extraMiles)) * float(rentalPeriod)
  42. elif rentalCode == "W":
  43. #here we are modifiying variables with operators to find our mile charge
  44. averageWeekMiles = float(totalMiles)/float(rentalPeriod)
  45. if averageWeekMiles <= 900:
  46. mileCharge = 0
  47. else:
  48. mileCharge = 100 * float(rentalPeriod)
  49.  
  50. amtDue = baseCharge + mileCharge
  51.  
  52. print("Rental Summary ")
  53. print("Rental Code: " + str(rentalCode))
  54. print("Rental Period: " + str(rentalPeriod))
  55. print("Starting Odometer: " + str(odoStart))
  56. print("Ending Odometer: " + str(odoEnd))
  57. print("Miles Driven: " + str(totalMiles))
  58. print("Amount Due: " + "$" + str("%.2f" %amtDue))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement