Python学习记录-2016-12-18
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Python学习记录-2016-12-18相关的知识,希望对你有一定的参考价值。
今日学习记录:
元组:
和list的区别是,元组只有两个操作,count和index,不能修改,添加,删除
购物车示例:
#!/usr/bin/env python # -*- coding: utf-8 -*- # Author:Jack Niu product_list = [ ("Iphone", 5888), ("Mac Pro", 11000), ("Bike", 899), ("Book", 78), ("Car", 300000) ] shoplist = [] salary = input("Input your salary>>>>>:") if salary.isdigit(): salary = int(salary) while True: for index, product in enumerate(product_list): print(index,product) select = input("输入你要选择的商品编号》》》》:") if select.isdigit(): select = int(select) if select < len(product_list) and select > -1: p_select = product_list[select] if p_select[1] <= salary: shoplist.append(p_select) salary -= p_select[1] print("添加%s成功,你的余额还剩\033[31;1m%s\033[0m元" %(p_select, salary)) else: print("你的余额只剩%s了,买不起你来干毛!" % salary) elif select == "q": print("---------Shopping list----------") for p in shoplist: print(p) print("你的余额还有%s" %salary) exit() else: print("无效的输入")
以上是关于Python学习记录-2016-12-18的主要内容,如果未能解决你的问题,请参考以下文章
[未解决问题记录]python asyncio+aiohttp出现Exception ignored:RuntimeError('Event loop is closed')(代码片段
ElasticSearch学习问题记录——Invalid shift value in prefixCoded bytes (is encoded value really an INT?)(代码片段