码迷,mamicode.com
首页 > 编程语言 > 详细

第一个python程序,购物车

时间:2017-08-13 14:20:32      阅读:177      评论:0      收藏:0      [点我收藏+]

标签:str   ber   append   mac   while   消费   continue   use   第一个   

第一个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程序,购物车

标签:str   ber   append   mac   while   消费   continue   use   第一个   

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

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