购物车程序,待完善
Posted dcentman
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了购物车程序,待完善相关的知识,希望对你有一定的参考价值。
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(‘余额不足‘)
以上是关于购物车程序,待完善的主要内容,如果未能解决你的问题,请参考以下文章