usr/bin/python
--coding:utf-8--
class DVD:
def __init__(self,name,price,status):
self.name = name
self.price = price
self.status = status
if name == "__main__":
# 0 未借出 1 借出
a = DVD("盗梦空间",10,1)
b = DVD("星际穿越",20,0)
c = DVD("黑客帝国",30,1)
dvds = {a.name:a,b.name:b,c.name:c}
print(dvds)
while True:
print("——————————DVD管理系统————————————")
print("1,查询所有DVD")
print("2,增加DVD")
print("3,借出DVD")
print('4,归还DVD')
print("5,退出")
print("----------------------------------------------------------")
i = int(input("请选择您要进行的操作:"))
if i == 5:
break
elif i == 1:
print("名称".center(20) + "价格".center(20) + "状态".center(10))
for key in dvds.keys():
print(dvds.get(key).status)
if dvds.get(key).status == 0:
print(key.center(18) + str(dvds.get(key).price).center(21) + "未借出".center(11))
else:
print(key.center(18) + str(dvds.get(key).price).center(21) + "已借出".center(11))
elif i == 2:
name = input("\t请输入要添加的DVD的名称:")
while name in dvds.keys():
name = input("\t该DVD已经存在,请重新输入:")
else:
price = input("\t请输入要添加的DVD的价格:")
new_dvd = DVD(name,price,0)
dvds[name] = new_dvd
print("添加成功!!!")
elif i == 3:
while True:
name = input("\t请输入要借出的DVD名称:")
if name not in dvds.keys():
print('\t\t没有该DVD,请重新输入!')
elif dvds.get(name).status == 1:
print('\t\t已经借出,请重新输入!')
else:
print("{}借出成功!!".format(name))
dvds.get(name).status = 1
break
elif i == 4:
while True:
name = input("\t请输入要归还的DVD名称:")
if name not in dvds.keys():
print("\t\t不存在,请重新输入!")
elif dvds.get(name).status == 0:
print("\t\t该DVD没有被借出,请新输入:")
else:
days = int(input("\t请输入借出天数:"))
print("请扫一扫:",int(dvds.get(name).price) * days,"元")
dvds.get(name).status = 0
print("归还成功!!")
网友评论