#!/usr/bin/env python3
# -*- coding: utf-8 -*-
# Author;Tsukasa product_list = [
('Iphone',5800),
('Mac Pro',9800),
('Bike',800),
('Watch',10600),
('Coffee',30),
('Tuskasa Python',20000),
] #创建一个商品列表
shopping_list = [] #创建一个购物车,空的list
salary = input('你的工资是多少:') #input让用户输入工资
if salary.isdigit():
salary = int(salary) #判断输入的是否数字,如果是的话改成int类型
while True: #进入循环
for index,list in enumerate(product_list): #enmuerate可以提取下标,提取product_list的下标,0.1.2.3....
print(index,list) #打印出商品列表的下标和list
user_choice = input('你要买什么商品:') #让用户输入购买商品的下标
if user_choice.isdigit():
user_choice = int(user_choice) #判断必须是数字,并int
if user_choice < len(product_list) and user_choice >=0:#设定输入范围,len()可以获取list的总数目,设定总数目为上线,并大于等于0
p_list = product_list[user_choice]#通过商品下标把商品取出来
if p_list[1] <= salary: #买得起、、,判断工资够
shopping_list.append(p_list)# 添加到shopping_list购物车
salary -= p_list[1]#扣工资
print('%s 已加入购物车,你现在还有%s元。'%(p_list,salary))
else:
print('没钱你买个J8啊')
exit()
else:
print('不要乱输入,请输入商品编号!') #没有商品下标
elif user_choice == "q":
print('-----shopping list-----')
for p in shopping_list:
print('你现在买了:',p)
print('你现在还剩%s元。' %(salary))
exit()
else:
print('不要乱输入,输入商品编号')

最新文章

  1. iscsi与multipath
  2. Java泛型 E、T、K、V、N
  3. VS2005中乱码问题
  4. 云计算分布式大数据Hadoop实战高手之路第八讲Hadoop图文训练课程:Hadoop文件系统的操作实战
  5. android-继承BaseAdapter--自定义适配器,getView执行多次的解决方法
  6. [转]C++学习心得
  7. mybatis配置方法
  8. MVC之Ajax
  9. 《Oracle Applications DBA 基础》- 9 - Concurrent Processing
  10. BZOJ_5296_[Cqoi2018]破解D-H协议_BSGS
  11. 流水车间调度算法分析的简单+Leapms实践--混合整数规划的启发式建模
  12. react-native-printer
  13. linux卸载openjdk
  14. 在排序数组中查找元素的第一个和最后一个位置(给定一个按照升序排列的整数数组 nums,和一个目标值 target。找出给定目标值在数组中的开始位置和结束位置。)
  15. MySQL 日期笔记
  16. 利用excel模板,将数据填充到excel中
  17. Docker:Docker machine(5)
  18. [How to]HBase集群备份方法--Replication机制
  19. Spring总结 2.装配bean
  20. Palindrome Numbers UVA - 12050(第几个回文数)

热门文章

  1. 【bzoj4236】JOIOJI STL-map
  2. [USACO06NOV]玉米田Corn Fields
  3. 【BZOJ 1485】[HNOI2009]有趣的数列 卡特兰数
  4. YUI Compressor是如何压缩JS代码的?
  5. How do I see what character set a database / table / column is in MySQL?
  6. 洛谷P1546 最短网络 Agri-Net
  7. session超时设置+超时页面跳转
  8. oracle12c创建用户等问题
  9. bzoj 1878 SDOI2009树状数组 离线操作
  10. Google Intern