功能:打印购物清单
"""
功能:打印购物清单类
时间:2019/12/17
"""
def display():
print("="*38)
print("="*11+"欢迎来到商品结算"+"="*11)
print("="*10+"k.输入商品信息页面"+"="*10)
print("="*10+"q.停止输入商品信息"+"="*10)
print("="*10+"a.结算清单商品信息"+"="*10)
print("="*10+"x.退出商品结算平台"+"="*10)
print("="*38)
class MyShopping():
def __init__(self,name,number,price):
self.name = name
self.number = number
self.price = price
def priceValues(self):
_price = self.number * self.price
return _price
if __name__ == "__main__":
display()
cyc1 = True
while cyc1:
aa = str(input("请输入您选择的业务: "))
if aa.title() == "K":
bb = []
cyc2 = True
while cyc2:
shopp = input("请输入购物信息:(商品名称)、(商品单价/元)、商品数量: ")
if str(shopp).title() == "Q":
cyc2 = False
else:
bb.append(shopp.split("、"))
if aa.title() == "A":
print("="*17+"虚拟超市购物清单"+"="*17)
print("商品名称 商品数量 商品单价 商品费用")
total = 0
for i in bb:
prices = MyShopping(i[0],int(i[1]),int(i[2])).priceValues()
print("%s %s %s %d/元"%(i[0],i[1],i[2],prices))
total += prices
print("="*50)
print("总计:{} 元".format(total))
if aa.title() == "X":
cyc1 = False
注:纸上得来终觉浅,绝知此事要躬行。