i want to ask you i want to store all informations in dictionary for this code but i can't i know that something i did wrong.I like to store informations from Customers if issue take a hourly , monthly or daily it is on BikeRental request bikes what i tried by far is any way?
class Customers:
def __init__(self,stock,unique_number,family_rent,salary):
self.issue_bill = {}
self.request_bikes = []
self.unique_number = unique_number
self.family_rent = family_rent
self.stock = stock
self.salary = salary
def available_bikes(self):
print("Unique number is: " , self.unique_number)
print("Stock available: " , self.stock)
print("Requested bikes at the moment are:", str(self.request_bikes)[1:-1])
def bike_hourly_basics(self,bike):
if self.stock < bike:
print("Not enough bikes on stock!")
else:
print("You can rent this bike for 10euro on hourly!")
self.stock = self.stock - bike
def bike_daily_basics(self,bike):
if self.stock < bike:
print("Not enough bikes on stock!")
elif bike == 0:
print("Enter positive integer , not zero")
else:
print("You can rent this bike for 30euro on daily!")
self.stock = self.stock - bike
def bike_weekly_basics(self,bike):
if self.stock < bike:
print("Not enough bikes on stock!")
elif bike == 0:
print("Enter positive integer , not zero")
else:
print("You can rent this bike for 60euro on weekly!")
self.stock = self.stock - bike
def family_rent(self):
if self.family_rent < 3:
print("Not enough people for the discount")
else:
print("Good job , the discount of 3 or more people is: " , self.salary - value )
class BikeRental:
def __init__(self):
self.all_accounts = {}
def request_bikes(self,stock,unique_number,family_rent,salary):
customer = Customers(stock,unique_number,family_rent,salary)
self.all_accounts[stock,unique_number] = customer
for key,value in self.all_accounts.items():
print(key)
customer = Customers(5 , 40607 , 4 , 5000)
bike = BikeRental()
bike.request_bikes(3,50607 , 5 , 6000)
CodePudding user response:
If you just wanted to store all information in a dictionary in request_bikes function then you can use something like below
def request_bikes(self, stock, unique_number, family_rent, salary):
customer = Customers(stock, unique_number, family_rent, salary)
#self.all_accounts[stock, unique_number] = customer
self.all_accounts['stock']= customer.stock
self.all_accounts['unique_number'] = customer.unique_number
self.all_accounts['family_rent'] = customer.family_rent
self.all_accounts['salary'] = customer.salary
return self.all_accounts