当前位置: 移动技术网 > IT编程>脚本编程>Python > python购物车程序

python购物车程序

2019年06月24日  | 移动技术网IT编程  | 我要评论

超级演说家黄小山,世奥得,蓝美琪照片

'''
1. 输入用户的工资
2.根据用户的工工资进行选择性的购买
3.最后打印用户购买的产品和用户的余额
'''
product_list = [
('iphone', 5000),
('mar pro', 8000),
('ipad', 7000),
('iphone', 15000)

]
shopping_list = list()
salary = input('请输入您的工资:')
if salary.isdigit():
salary = int(salary)
while true:
for index, item in enumerate(product_list):
print(index, 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 = salary - p_item[1]
print('您的余额是{}'.format(salary))
elif p_item[1] > salary:
print('您的余额不多,无法进行交易')
else:
print('商品不存在')
elif user_choice == 'q':
print('-----shopping list-------')
for p in shopping_list:
print(p)
print('您的余额是{}'.format(salary))
exit()

else:
print('输入有误')

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网