首页 > 编程语言 > 详细

第一个python程序,购物车

时间:2017-08-13 13:52:40      阅读:216      评论:0      收藏:0      [点我收藏+]

第一个pyhone程序,简单的购物车功能,刚开始学习,练习下手感。

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

salary = int(raw_input("请输入您的工资:").strip())

shop_list=[[1,‘iphone6s‘,5800],[2,‘mac book‘,9000],[3,‘coff‘,32],[4,‘python book‘,80],[5,‘bicyle‘,1500]]
user_list=[]

print(‘‘‘商品列表如下:
1.iphone6s 5800
2.mac book 9000
3.coff 32
4.pyhone book 80
5.bicyle 1500
‘‘‘)

while True:
  select = int(raw_input("请选择需要购买的商品编号:").strip())

  if select >= len(shop_list):
    print("商品编号不存在,请重新输入!")
    continue
  else:
    Number = shop_list[select-1][0]
    Product = shop_list[select-1][1]
    Price = shop_list[select-1][2]

  if salary >= Price:
    user_list.append(Product)
    salary = salary - Price
    print("已购买商品:%s") %str(user_list)
    print("已消费%s元,余额为%s元。") %(Price,salary)
    continue
  else:
    Difference = Price - salary
    print("您的工资无法满足此产品价格,还差%s元,请重新选择其他商品!") %Difference
    continue

第一个python程序,购物车

原文:http://www.cnblogs.com/qiyuanchang/p/7353271.html

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