标签:lis put for 登录 user word name price 电脑
goods = [ {‘name‘: ‘电脑‘, ‘price‘: 5999}, {‘name‘: ‘鼠标‘, ‘price‘: 99}, {‘name‘: ‘键盘‘, ‘price‘: 299}, {‘name‘: ‘游艇‘, ‘price‘: 399999}, {‘name‘: ‘女朋友‘, ‘price‘: 999} ] from_db_username = ‘jason‘ from_db_password = 123 i = 0 flag = True while flag: while i < 3: username = input(‘请输入用户名:‘) password = int(input(‘请输入密码:‘)) if from_db_username == username and from_db_password == password: print(‘登录成功‘) flag = False break else: i += 1 print(‘登录失败,您还有%s次机会‘ % (3 - i)) else: answer = input(‘是否继续,是输入y,否输入q:‘) if answer == ‘y‘: i = 0 elif answer == ‘q‘: break salary = int(input(‘请输入您的工资:‘)) goods_list = {} price_list = {} k = 1 for i in goods: goods_list.setdefault(k, i[‘name‘]) price_list.setdefault(i[‘name‘], i[‘price‘]) k += 1 print(goods_list) print(price_list) goods_num = int(input(‘请输入您要买的商品编号:‘)) if salary > price_list[goods_list[goods_num]]: mon_left = price_list[goods_list[goods_num]] else: print(‘余额不足‘)
标签:lis put for 登录 user word name price 电脑
原文地址:https://www.cnblogs.com/DcentMan/p/11123563.html