输入工资,买东西的程序
goods = [
{"name": "电脑", "price": 1999},
{"name": "鼠标", "price": 10},
{"name": "游艇", "price": 20},
{"name": "美女", "price": 998},
]
用户信息:
user = {"username":"lubenwei", "password": "123456"}
功能要求:
1、启动程序后,输入用户名密码后,让用户输入工资,然后打印商品列表
2、用户根据商品编号购买商品
3、用户选择商品后,检测余额是否够,够就直接扣款,不够就提醒
4、退出时,打印已购买商品和余额
goods = [ {"name": "电脑", "price": 1999}, {"name": "鼠标", "price": 10}, {"name": "游艇", "price": 20}, {"name": "美女", "price": 998}, ] user = {"username":"lubenwei", "password": "123456"} lis = [] while 1 : a = input("请输入用户名:") b = input("请输入密码:") if a == user["username"] and b == user["password"] : print("登陆成功") x = int(input("请输入你的工资:")) for i in range(len(goods)) : print(i+1,goods[i]["name"],goods[i]["price"]) while 1 : y = input("请输入你想买的序列号:") if y.isdigit() == True : if int(y) <= len(goods) and int(y) > 0 and x >= goods[int(y)-1]["price"]: print("您购买了%s,还有%s元"%(goods[int(y)-1]["name"],x - goods[int(y)-1]["price"])) x = x - goods[int(y) - 1]["price"] lis.append("您购买了%s,还有%s元"%(goods[int(y)-1]["name"],x)) elif int(y) <= len(goods) and int(y) > 0 and x < goods[int(y) - 1]["price"]: print("您余额不足,请选择别的商品") else : print("您输入错误,请重新选择") elif y.upper() == "Q" : break else : print("输入错误,请重新输入") print(lis) break else : print("账号密码错误,请重新输入.")