global count
global n
count = 100
n = 0
import random
class Store:
def __init__(self):
self.db = {}
self.list1 = []
self.count = count
self.n = n
def cunbao(self):
if(self.n==1):
pw = str(random.randint(100000,999999))
b = pw[1:]
c = str(random.randint(0,9))
pw = b + c
self.db[pw] = self.n
print("您的存包密码是",pw)
print(self.db[pw],"号柜门已经打开,请开始存包")
print("此时已经使用了",self.n,"个储物柜")
print("还剩余",self.count,"个储物柜\n")
self.list1.append(pw)
else:
pw = str(random.randint(100000,999999))
b = pw[1:]
c = str(random.randint(0,9))
pw = b + c
if pw in self.list1:
return self.cunbao(n)
if pw not in self.list1:
self.db[pw] = self.n
print("您的存包密码是",pw)
print(self.db[pw],"号柜门已经打开,请开始存包")
print("目前已使用了",self.n,"个储物柜")
print("还剩余",self.count,"个储物柜")
self.list1.append(pw)
def qubao(self,pw):
if pw in self.db:
self.n-=1
self.count+=1
print(self.db[pw],"号柜门已打开,请开始取包")
print("目前已使用了",self.n,"个储物柜")
print("还剩余",self.count,"个储物柜\n")
print("\n")
del self.db[pw]
self.list1.remove(pw)
else:
print("密码输入错误")
def abc(self):
print("请输入取包指令2进行取包:")
b = input()
if(b=='2'):
print("请开始输入你的密码:")
pw = input()
self.qubao(pw)
else:
return self.abc()
def shuru(self):
while(self.count>0):
print("请输入存包指令1进行存包,输入2进行取包:\n")
b = input()
if(b=='1'):
self.n+=1
self.count-=1
self.cunbao()
if(self.count == 0):
print("柜子已经用完\n")
self.abc()
else:
print("\n")
elif(b=='2'):
print("请开始输入密码")
pw = input()
self.qubao(pw)
else:
print("温馨提示:一定要输入1进行存包")
def main():
a = Store()
a.shuru()
main()
模拟超市存包代码
最新推荐文章于 2020-12-07 11:32:47 发布