标签:product python 购物车 记录 count
今日学习记录:
元组:
和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("无效的输入")标签:product python 购物车 记录 count
原文地址:http://12306114.blog.51cto.com/12296114/1883812