标签:none not bsp hid while ide ace 打印 编号
基础需求:
user="xiaojin" password=123456 count=0 while count<3: name=input("user>>:") if name != user: count += 1 continue passwd=int(input("password>>:")) if passwd!=password: count += 1 continue print ("ok") break else: exit() msg_dic=[ (‘Iphone‘, 5800), (‘Mac‘, 9800), (‘Bike‘, 800), (‘Iwatch‘, 3000), (‘Coffee‘, 31), (‘Pen‘, 100) ] shop_list=[] while True: money=input("请输入你的工资:") if not money.isdigit(): continue else: money=int(money) break while True: til="欢迎购买" print(til.center(32,"-")) for key,item in enumerate(msg_dic): print ("商品编号\033[31;m%s\033[0m,商品为\033[31;m%s\033[0m,价格为\033[31;m%s\033[0m"%(key,item[0].ljust(8),item[1])) goods=input("请输入你要买的商品编号:") if goods.isdigit(): goods=int(goods) if goods>=0 and goods<len(msg_dic): every_shop=msg_dic[goods] print (every_shop) if money>=every_shop[1]: shop_list.append(msg_dic[goods]) money=money-every_shop[1] print ("你的工资还有\033[31;m%s\033[0m,你购买的商品是\033[31;m%s\033[0m"%(money,every_shop[0])) else: print ("你的工资不购买商品%s,按q退出,你当前的工资为\033[31;m%s\033[0m"%(every_shop[0],money)) else: print ("你选的购物编号不存在,请重新输入按q退出") elif goods=="q": for k in shop_list: print ("购买商品%s,商品价格%s"%(k[0],k[1])) print ("你当前的金额为\033[31;m%s\033[0m"%(money)) exit() else: print ("请重新输入")
标签:none not bsp hid while ide ace 打印 编号
原文地址:http://www.cnblogs.com/so-cool/p/7524205.html