码迷,mamicode.com
首页 > 其他好文 > 详细

shoppingcar

时间:2018-02-10 15:51:43      阅读:151      评论:0      收藏:0      [点我收藏+]

标签:car   bsp   余额   购物   pytho   mac pro   分隔符   use   list   

b编写的一个小程序,中间对于列表中的分隔符(,),没有输入使得程序无法运行,后来还有(%s)的使用不熟练,也是错误点。

 

 


#!/usr/bin/env python
# -*- coding: utf-8 -*-

shoping_list=[]

product = [
("iphone",5800),
(‘mac pro‘,9800),
(‘bike‘,800),
(‘watch‘,8500),
(‘coffe‘,31),

]
salary = input("你的收入:")
if salary.isdigit():
salary = int(salary)
while True:
for index,item in enumerate(product):
print(index,item)
user_choice = input("选择商品:")
if user_choice.isdigit():
user_choice = int(user_choice)
if user_choice <len(product) and user_choice >= 0:
p_item = product[user_choice]
if p_item[1] <= salary:
shoping_list.append(p_item)
salary = salary - p_item[1]

print("添加 %s到你的购物车上,你现在的余额是%s"%(p_item[0], salary))
else:
print(‘\033[41:1m你的余额只剩[%s]啦,购买不了、033[om‘%salary)
else:
print("产品编码[%s]不存在"%user_choice)
elif user_choice == ‘q‘:
print(‘----------购物清单------‘)
for p in shoping_list :
print(p)
print(‘你现在的余额是:‘,salary)
exit()
else:
print(‘不可选择‘)


shoppingcar

标签:car   bsp   余额   购物   pytho   mac pro   分隔符   use   list   

原文地址:https://www.cnblogs.com/monkeyjz2018/p/8438789.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!