Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import datetime #import datetime from library
- import random #Import random from libra
- number_of_bikes = 100
- tags = ["BK{0:03}".format(i) for i in range(1,number_of_bikes+1)] #Float Bikes from OO1 to 003
- rental_codes = [code for code in range(200,900)] #List Comprehensions from 1000 to 2000
- rent_detils = {} #Transaction details made an Empty Dictionary
- class Rental_system():
- def __init__(self,bikes_available=number_of_bikes):
- self.bike_available = number_of_bikes
- global rent_detils
- self.bike_tags = tags
- class customer(Rental_system) :
- def choices(self):
- global number_of_bikes, tags
- self.date_time = datetime.datetime.now()
- duration = input("Please input your type of rental period: ")
- self.duration = duration
- self.bike_tag = []
- if self.duration== 'hourly':
- self.amount_of_bikes = int(input("How many bike(s) do you want to rent: "))
- self.rent_duration = int(input("For how many hours do you want to rent: "))
- if self.amount_of_bikes < self.bike_available:
- self.bike_tag = self.bike_tags[:self.amount_of_bikes]
- tags = [bike for bike in tags if bike not in self.bike_tag]
- self.name = str(input("Please insert your fullname here: "))
- self.hourly_rental(self.amount_of_bikes, self.rent_duration)
- number_of_bikes -= self.amount_of_bikes
- else:
- print('Not enough bikes available for rental!')
- elif self.duration == 'daily':
- self.amount_of_bikes = int(input("How many bike(s) do you want to rent: "))
- self.rent_duration = int(input("For how many days do you want to rent: "))
- if self.amount_of_bikes < self.bike_available:
- self.bike_tag = self.bike_tags[:self.amount_of_bikes]
- tags = [bike for bike in tags if bike not in self.bike_tag]
- self.name = str(input("Please insert your fullname here: "))
- self.daily_rental(self.amount_of_bikes, self.rent_duration)
- number_of_bikes -= self.amount_of_bikes
- else:
- print('Not enough bikes available for rental!')
- elif self.duration == 'weekly':
- self.amount_of_bikes = int(input("How many bike(s) do you want to rent: "))
- self.rent_duration = int(input("For how many weeks do you want to rent: "))
- if self.amount_of_bikes < self.bike_available:
- self.bike_tag = self.bike_tags[:self.amount_of_bikes]
- tags = [bike for bike in tags if bike not in self.bike_tag]
- self.name = str(input("Please insert your fullname here: "))
- self.weekly_rental(self.amount_of_bikes, self.rent_duration)
- number_of_bikes -= self.amount_of_bikes
- else:
- print('Not enough bikes available for rental!')
- else:
- print('Error!, Please insert an appropriate rental period')
- def billing(self):
- self.borrow_time = str(self.date_time.year)+'-'+str(self.date_time.month)+'-'+str(self.date_time.day) + ' ' + 'Time:'+ self.date_time.strftime("%I")+':'+ self.date_time.strftime("%M")+self.date_time.strftime("%p")
- self.dued_time = str(self.due_time.year)+'-'+str(self.due_time.month)+'-'+str(self.due_time.day) + ' ' 'Due time:'+ self.due_time.strftime("%I")+':'+ self.due_time.strftime("%M")+self.due_time.strftime("%p")
- if self.amount_of_bikes < 1:
- print('Please how many bikes do you want to rent?')
- elif self.amount_of_bikes in range(3,6):
- print("\nCongratulations you're eligible for the family rental discount")
- total_amount = (self.amount_of_bikes * self.rent_duration * self.amount_per_period)
- discount_amount = total_amount * 0.3
- self.amount_to_pay = total_amount - discount_amount
- elif self.amount_of_bikes in range(1,2):
- self.amount_to_pay = (self.amount_of_bikes * self.rent_duration * self.amount_per_period)
- def hourly_rental(self, amount_of_bikes, no_of_hours):
- print('You will be charged $5 per hour')
- self.amount_per_period = 5
- self.amount_of_bikes = amount_of_bikes
- self.no_of_hours = self.rent_duration
- self.rental_type = 'hour(s)'
- self.due_time = self.date_time + datetime.timedelta(hours = self.rent_duration)
- self.billing()
- self.generate_code()
- self.invoice()
- def daily_rental(self, amount_of_bikes, no_of_days):
- print('You will be charged $20 per day')
- self.amount_per_period = 20
- self.amount_of_bikes = amount_of_bikes
- self.days = self.rent_duration
- self.rental_type = 'day(s)'
- self.due_time = self.date_time + datetime.timedelta(hours = self.rent_duration*24)
- self.generate_code()
- self.billing()
- self.invoice()
- def weekly_rental(self, amount_of_bikes, no_of_weeks):
- print('You will be charged $60 per week')
- self.amount_per_period = 60
- self.amount_of_bikes = amount_of_bikes
- self.no_of_weeks = self.rent_duration
- self.rental_type = 'week(s)'
- self.due_time = self.date_time + datetime.timedelta(hours = self.rent_duration*24*7)
- self.generate_code()
- self.billing()
- self.invoice()
- def generate_code(self):
- global rental_codes, rent_detils, tags
- self.customer_code = random.choice(rental_codes)
- rent_detils.update({ self.customer_code : [self.customer_code, self.name, self.duration, self.amount_of_bikes, self.rent_duration, self.rental_type, self.bike_tag]})
- rental_codes.remove(self.customer_code)
- def invoice(self):
- print("\nBIKE RENTAL INVOICE")
- print("Name:", self.name,)
- print("Rental code:", self.customer_code)
- print("Rental period type:", self.duration)
- print('Amount of bike(s) rented:', self.amount_of_bikes)
- print("Rental period duration:", self.rent_duration, self.rental_type)
- print("Day of rental:", self.borrow_time)
- print("Due date:", self.dued_time)
- print("Amount to pay:", str(self.amount_to_pay)+'$')
- print("Rented bike tags:", *self.bike_tag, sep = ', ')
- def returnbike(self):
- global number_of_bikes
- code = int(input('Enter your Rental code : '))
- if code in rent_detils:
- details = rent_detils.get(code)
- print("\nBIKE RENTAL DETAILS")
- print("Your Name:", details[1],)
- print("Rental code:", details[0])
- print("Rental period type:", details[2])
- print('Amount of bike rented:', details[3])
- print("Rental duration:", details[4], details[5])
- print("Rental Code:", details[6])
- print('Returned!!!')
- del rent_detils[code]
- number_of_bikes += details[3]
- for i in self.bike_tags:
- self.bike_tags.remove(i)
- else:
- print("Invalid passcode!!!")
- while True:
- transaction = input("Welcome to Our Bike Shop, do you want to Rent or Return? : ")
- transaction = transaction.upper()
- if transaction == 'RENT':
- print('\nRight now, we have', number_of_bikes, 'bikes available for rental')
- print()
- print('''You can rent bikes on hourly basis for $5 per hour.
- You can rent bikes on daily basis for $20 per day.
- You can rent bikes on weekly basis for $60 per week.
- You can also have rental discounts for 3 to 5 bike rentals.\n
- Type in (hourly,daily or weekly) depending on your choice of rental period''')
- customer1= customer()
- customer1.choices()
- elif transaction == 'RETURN':
- customer1= customer()
- customer1.returnbike()
- else:
- print("Please input an appropraite option")
Add Comment
Please, Sign In to add comment