dprincef

Untitled

Jun 10th, 2020
173
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 8.11 KB | None | 0 0
  1. import datetime  #import datetime from library
  2. import random   #Import random from libra
  3. number_of_bikes = 100
  4. tags = ["BK{0:03}".format(i) for i in range(1,number_of_bikes+1)] #Float Bikes from OO1 to 003
  5. rental_codes = [code for code in range(200,900)] #List Comprehensions from 1000 to 2000
  6. rent_detils = {} #Transaction details made an Empty Dictionary
  7. class Rental_system():
  8.     def __init__(self,bikes_available=number_of_bikes):
  9.         self.bike_available = number_of_bikes
  10.         global rent_detils
  11.         self.bike_tags = tags
  12.  
  13.  
  14.  
  15.            
  16.  
  17. class customer(Rental_system) :
  18.     def choices(self):
  19.         global number_of_bikes, tags
  20.         self.date_time = datetime.datetime.now()
  21.         duration = input("Please input your type of rental period: ")
  22.         self.duration = duration
  23.         self.bike_tag = []
  24.         if self.duration== 'hourly':
  25.             self.amount_of_bikes = int(input("How many bike(s) do you want to rent: "))
  26.             self.rent_duration = int(input("For how many hours do you want to rent: "))
  27.             if self.amount_of_bikes < self.bike_available:
  28.                 self.bike_tag = self.bike_tags[:self.amount_of_bikes]
  29.                 tags = [bike for bike in tags if bike not in self.bike_tag]
  30.                 self.name = str(input("Please insert your fullname here: "))
  31.                 self.hourly_rental(self.amount_of_bikes, self.rent_duration)
  32.                 number_of_bikes -= self.amount_of_bikes
  33.            
  34.             else:
  35.                 print('Not enough bikes available for rental!')
  36.  
  37.         elif self.duration == 'daily':
  38.             self.amount_of_bikes = int(input("How many bike(s) do you want to rent: "))
  39.             self.rent_duration = int(input("For how many days do you want to rent: "))
  40.             if self.amount_of_bikes < self.bike_available:
  41.                 self.bike_tag = self.bike_tags[:self.amount_of_bikes]
  42.                 tags = [bike for bike in tags if bike not in self.bike_tag]
  43.                 self.name = str(input("Please insert your fullname here: "))
  44.                 self.daily_rental(self.amount_of_bikes, self.rent_duration)
  45.                 number_of_bikes -= self.amount_of_bikes
  46.            
  47.             else:
  48.                 print('Not enough bikes available for rental!')
  49.  
  50.         elif self.duration == 'weekly':
  51.             self.amount_of_bikes = int(input("How many bike(s) do you want to rent: "))
  52.             self.rent_duration = int(input("For how many weeks do you want to rent: "))
  53.             if self.amount_of_bikes < self.bike_available:
  54.                 self.bike_tag = self.bike_tags[:self.amount_of_bikes]
  55.                 tags = [bike for bike in tags if bike not in self.bike_tag]
  56.                 self.name = str(input("Please insert your fullname here: "))
  57.                 self.weekly_rental(self.amount_of_bikes, self.rent_duration)
  58.                 number_of_bikes -= self.amount_of_bikes
  59.            
  60.             else:
  61.                 print('Not enough bikes available for rental!')
  62.  
  63.         else:
  64.             print('Error!, Please insert an appropriate rental period')    
  65.     def billing(self):
  66.         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")
  67.         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")
  68.         if self.amount_of_bikes < 1:
  69.             print('Please how many bikes do you want to rent?')
  70.         elif self.amount_of_bikes in range(3,6):
  71.             print("\nCongratulations you're eligible for the family rental discount")
  72.             total_amount = (self.amount_of_bikes * self.rent_duration * self.amount_per_period)
  73.             discount_amount = total_amount * 0.3
  74.             self.amount_to_pay = total_amount - discount_amount
  75.        
  76.         elif self.amount_of_bikes in range(1,2):
  77.             self.amount_to_pay = (self.amount_of_bikes * self.rent_duration * self.amount_per_period)
  78.    
  79.    
  80.     def hourly_rental(self, amount_of_bikes, no_of_hours):
  81.         print('You will be charged $5 per hour')
  82.         self.amount_per_period = 5
  83.         self.amount_of_bikes = amount_of_bikes
  84.         self.no_of_hours = self.rent_duration
  85.         self.rental_type = 'hour(s)'
  86.         self.due_time = self.date_time + datetime.timedelta(hours = self.rent_duration)
  87.         self.billing()
  88.         self.generate_code()
  89.         self.invoice()
  90.  
  91.     def daily_rental(self, amount_of_bikes, no_of_days):
  92.         print('You will be charged $20 per day')
  93.         self.amount_per_period = 20
  94.         self.amount_of_bikes = amount_of_bikes
  95.         self.days = self.rent_duration
  96.         self.rental_type = 'day(s)'
  97.         self.due_time = self.date_time + datetime.timedelta(hours = self.rent_duration*24)
  98.         self.generate_code()
  99.         self.billing()
  100.         self.invoice()
  101.  
  102.     def weekly_rental(self, amount_of_bikes, no_of_weeks):
  103.         print('You will be charged $60 per week')
  104.         self.amount_per_period = 60
  105.         self.amount_of_bikes = amount_of_bikes
  106.         self.no_of_weeks = self.rent_duration
  107.         self.rental_type = 'week(s)'
  108.         self.due_time = self.date_time + datetime.timedelta(hours = self.rent_duration*24*7)
  109.         self.generate_code()
  110.         self.billing()
  111.         self.invoice()
  112.  
  113.    
  114.            
  115.        
  116.        
  117.  
  118.     def generate_code(self):
  119.         global rental_codes, rent_detils, tags
  120.         self.customer_code = random.choice(rental_codes)
  121.         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]})
  122.         rental_codes.remove(self.customer_code)
  123.    
  124.     def invoice(self):
  125.         print("\nBIKE RENTAL INVOICE")
  126.         print("Name:", self.name,)
  127.         print("Rental code:", self.customer_code)
  128.         print("Rental period type:", self.duration)
  129.         print('Amount of bike(s) rented:', self.amount_of_bikes)
  130.         print("Rental period duration:", self.rent_duration, self.rental_type)
  131.         print("Day of rental:", self.borrow_time)
  132.         print("Due date:", self.dued_time)
  133.         print("Amount to pay:", str(self.amount_to_pay)+'$')
  134.         print("Rented bike tags:", *self.bike_tag, sep = ', ')
  135.    
  136.  
  137.     def returnbike(self):
  138.         global number_of_bikes
  139.        
  140.         code = int(input('Enter your Rental code : '))
  141.         if code in rent_detils:
  142.             details = rent_detils.get(code)
  143.             print("\nBIKE RENTAL DETAILS")
  144.             print("Your Name:", details[1],)
  145.             print("Rental code:", details[0])
  146.             print("Rental period type:", details[2])
  147.             print('Amount of bike rented:', details[3])
  148.             print("Rental duration:", details[4], details[5])
  149.             print("Rental Code:", details[6])
  150.            
  151.             print('Returned!!!')
  152.            
  153.             del rent_detils[code]
  154.             number_of_bikes += details[3]
  155.             for i in self.bike_tags:
  156.                 self.bike_tags.remove(i)
  157.        
  158.            
  159.         else:
  160.             print("Invalid passcode!!!")
  161.  
  162. while True:
  163.     transaction = input("Welcome to Our Bike Shop, do you want to Rent or Return?  : ")
  164.     transaction = transaction.upper()
  165.     if transaction == 'RENT':
  166.         print('\nRight now, we have', number_of_bikes, 'bikes available for rental')
  167.         print()
  168.         print('''You can rent bikes on hourly basis for $5 per hour.
  169.    You can rent bikes on daily basis for $20 per day.
  170.    You can rent bikes on weekly basis for $60 per week.
  171.    You can also have rental discounts for 3 to 5 bike rentals.\n
  172.    Type in (hourly,daily or weekly) depending on your choice of rental period''')
  173.        
  174.         customer1= customer()
  175.         customer1.choices()
  176.  
  177.     elif transaction ==  'RETURN':
  178.         customer1= customer()
  179.         customer1.returnbike()
  180.  
  181.     else:
  182.         print("Please input an appropraite option")
Add Comment
Please, Sign In to add comment