首页 > 其他 > 详细

shoppingcar

时间:2018-02-10 15:27:25      阅读:196      评论:0      收藏:0      [点我收藏+]

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

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

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!