fork download
  1. import datetime
  2.  
  3. class CarRental:
  4. def __init__(self, stock=0):
  5. self.stock = stock
  6.  
  7. def DisplayStock(self):
  8. print("We have {} cars available for renting.".format(self.stock))
  9. return self.stock
  10.  
  11. def HourlyBasis(self, n):
  12. if n <= 0:
  13. print("Minimum number of cars to rent should be at least one.")
  14. elif n > self.stock:
  15. print("Sorry! We only have {} cars available to rent at the moment.".format(self.stock))
  16.  
  17. now = datetime.datetime.now()
  18. print("You have rented {} cars at {} hours".format(n, now.hour))
  19. print("You will be charged $5 per hour")
  20. print("Thanks for opting our service.")
  21. self.stock = self.stock - n
  22. return now
  23.  
  24.  
  25. def DailyBasis(self, n):
  26. if n <= 0:
  27. print("Minimum number of cars to rent should be at least one.")
  28. elif n > self.stock:
  29. print("Sorry! We only have {} cars available to rent at the moment.".format(self.stock))
  30. else:
  31. now = datetime.datetime.now()
  32. print("You have rented {} cars at {} hours".format(n, now.hour))
  33. print("You will be charged $100 per day")
  34. print("Thanks for opting our service.")
  35. self.stock = self.stock - n
  36. return now
  37.  
  38.  
  39.  
  40. def WeeklyBasis(self, n):
  41. if n <= 0:
  42. print("Minimum number of cars to rent should be at least one.")
  43. elif n > self.stock:
  44. print("Sorry! We only have {} cars available to rent at the moment.".format(self.stock))
  45. else:
  46. now = datetime.datetime.now()
  47. print("You have rented {} cars at {} hours".format(n, now.hour))
  48. print("You will be charged $500 per week")
  49. print("Thanks for opting our service.")
  50. self.stock = self.stock - n
  51. return now
  52.  
  53.  
  54. def ReturnCar(self, request):
  55. RentalTime, RentalBasis, NumberofCars = request
  56. bill = 0
  57. if RentalTime and RentalBasis and NumberofCars:
  58. self.stock += NumberofCars
  59. now = datetime.datetime.now()
  60. RentalPeriod = now - RentalTime
  61.  
  62. if RentalBasis == 1:
  63. bill = round(RentalPeriod.seconds / 3600) * 5 * NumberofCars
  64.  
  65. elif RentalBasis == 2:
  66. bill = round(RentalPeriod.days) * 100 * NumberofCars
  67.  
  68. elif RentalBasis == 3:
  69. bill = round(RentalPeriod.days / 7) * 500 * NumberofCars
  70.  
  71. print("The car has been returned. Hope you enjoyed our service!")
  72. print("Total Amount Payable: ${}".format(bill))
  73. return bill
  74.  
  75. else:
  76. print("Are you sure you rented a car with us?")
  77. return None
  78.  
Success #stdin #stdout 0.02s 7204KB
stdin
Standard input is empty
stdout
Standard output is empty