我想问你,我想在字典中存储这段代码的所有信息,但我不能,我知道我做错了什么。我喜欢从客户那里存储信息,如果问题需要每小时,每月或每天,它是在BikeRental请求自行车,我尝试了什么方法?
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)
如果您只是想在request_bikes函数中将所有信息存储在字典中,那么您可以使用下面的内容
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