import datetime
class CarRental:
def __init__(self, stock=0):
self.stock = stock
def DisplayStock(self):
print("We have {} cars available for renting.".format(self.stock))
return self.stock
def HourlyBasis(self, n):
if n <= 0:
print("Minimum number of cars to rent should be at least one.")
elif n > self.stock:
print("Sorry! We only have {} cars available to rent at the moment.".format(self.stock))
now = datetime.datetime.now()
print("You have rented {} cars at {} hours".format(n, now.hour))
print("You will be charged $5 per hour")
print("Thanks for opting our service.")
self.stock = self.stock - n
return now
def DailyBasis(self, n):
if n <= 0:
print("Minimum number of cars to rent should be at least one.")
elif n > self.stock:
print("Sorry! We only have {} cars available to rent at the moment.".format(self.stock))
else:
now = datetime.datetime.now()
print("You have rented {} cars at {} hours".format(n, now.hour))
print("You will be charged $100 per day")
print("Thanks for opting our service.")
self.stock = self.stock - n
return now
def WeeklyBasis(self, n):
if n <= 0:
print("Minimum number of cars to rent should be at least one.")
elif n > self.stock:
print("Sorry! We only have {} cars available to rent at the moment.".format(self.stock))
else:
now = datetime.datetime.now()
print("You have rented {} cars at {} hours".format(n, now.hour))
print("You will be charged $500 per week")
print("Thanks for opting our service.")
self.stock = self.stock - n
return now
def ReturnCar(self, request):
RentalTime, RentalBasis, NumberofCars = request
bill = 0
if RentalTime and RentalBasis and NumberofCars:
self.stock += NumberofCars
now = datetime.datetime.now()
RentalPeriod = now - RentalTime
if RentalBasis == 1:
bill = round(RentalPeriod.seconds / 3600) * 5 * NumberofCars
elif RentalBasis == 2:
bill = round(RentalPeriod.days) * 100 * NumberofCars
elif RentalBasis == 3:
bill = round(RentalPeriod.days / 7) * 500 * NumberofCars
print("The car has been returned. Hope you enjoyed our service!")
print("Total Amount Payable: ${}".format(bill))
return bill
else:
print("Are you sure you rented a car with us?")
return None