Python基础小笔记《2017-10-03》
来源:互联网 发布:网络营销 知乎 编辑:程序博客网 时间:2024/05/14 09:16
一、购物车小程序
product_list = [ ('iphone',5800), ('Mac book',9800), ('Bike',800), ('iWatch',10600), ]shopping_list = []salary = input("input your salary:")if salary.isdigit(): salary = int(salary) while True: for item in product_list: print(product_list.index(item),item) user_choice = input("选择要买的序号:") if user_choice.isdigit(): user_choice = int(user_choice) if user_choice < len(product_list) and user_choice >= 0: p_item = product_list[user_choice] if p_item[1] <= salary: #买得起 shopping_list.append(p_item) salary -= p_item[1] print('Added %s into shopping cart, your current balance is %s' %(p_item,salary)) else: print("Your salary is not enough!!!") elif user_choice == 'q' or user_choice == 'Q': print('Your shopping list:') for p in shopping_list: print(p) print('Your current balance: ', salary) break else: print('invalid option')
阅读全文
0 0
- Python基础小笔记《2017-10-03》
- Python基础小笔记《2017-10-04》
- Python基础小笔记《2017-10-07》
- Python基础小笔记《2017-10-17》
- Python基础小笔记《2017-10-18》
- Python基础小笔记《2017-09-24》
- Python基础小笔记《2017-09-27》
- python 3.0学习笔记之二------python基础小知识
- Python基础小实例
- 小甲鱼python 基础
- [Python] Python基础笔记
- 小笔记-java基础
- 小笔记-mysql基础
- 零基础学python途中遇到的这些小问题——小更新笔记
- python小笔记
- python 小知识点笔记
- python小笔记
- Python 学习小笔记
- C语言函数指针基础
- 计蒜客 A.Artwork 并查集+set
- 10月3日 c语言输入100-200之间不能被3整除的整数
- 汉诺塔问题 hanoi(递归)
- 损失函数
- Python基础小笔记《2017-10-03》
- Jzoj3906 魏传之长坂逆袭(梦回三国系列)
- 判断两个等长数组中元素是否一样,如不一样,输出不一样的元素
- *【bzoj 1001】狼抓兔子(最小割)
- java——内部类
- Java值传递与引用传递
- POI导出Excel表格:有样式、图片导出
- kubelet 源码分析:statusManager 和 probeManager
- POJ 2352|URAL 1028|Stars|树状数组