标签:pen print python NPU .com info color put_user put
1 # coding=utf-8 2 name_l = [] 3 passwd_l = [] 4 money_l = [] 5 goods = {} 6 index = 0 7 def input_user(): 8 print("输入个人信息:") 9 while True: 10 name = input("name: ") 11 if name == "结束!": 12 break 13 passwd = input("passwd: ") 14 money = float(input("money: ")) 15 name_l.append(name) 16 passwd_l.append(passwd) 17 money_l.append(money) 18 19 20 def login(): 21 print("登录:") 22 suc = False 23 while not suc: 24 name = input("name: ") 25 if name not in name_l: 26 print("用户名不存在") 27 continue 28 passwd = input("passwd: ") 29 30 global index 31 index = name_l.index(name) 32 if passwd == passwd_l[index]: 33 print("登录成功") 34 suc = True 35 else: 36 print("密码错误") 37 38 39 def input_goods(): 40 print("商品:") 41 while True: 42 name_goods = input("goods_name: ") 43 if name_goods == "结束!": 44 break 45 price = input("price: ") 46 goods[name_goods] = int(price) 47 48 def input_buy(): 49 print("购买:") 50 while True: 51 name_goods = input("buy_goods_name: ") 52 if name_goods not in goods: 53 print("商品不存在!") 54 continue 55 amount = int(input("amount: ")) 56 if money_l[index] < goods[name_goods] * amount: 57 print("余额不足") 58 break 59 else: 60 money_l[index] -= goods[name_goods] * amount 61 print("购买成功", "余额%f" % money_l[index]) 62 63 64 input_user() 65 input_goods() 66 login() 67 input_buy()
标签:pen print python NPU .com info color put_user put
原文地址:https://www.cnblogs.com/pangzx/p/9371262.html