1.要求

  • 启动程序后,让用户输入工资,然后打印商品列表
  • 允许用户genuine商品编号购买商品
  • 用户选择商品后,检测余额是否够,够就直接扣款,不够就提醒还有多少
  • 可随时退出,退出时,打印已购买商品和余额

code:

 #Author:Daniel
# -*- coding: utf-8 -*-
#time:2017.10.26-10:10
Commodity = [
('IPhone',6800),
('Samsung',7000),
('Huwei',10000),
('Mi',11000),
('vivo',12000),
('NOKIA',15000),
]
shopping_cart = []
salary = input('Please enter your salary:')
if salary.isdigit():
salary = int(salary)
while True:
for index,Commodity_list in enumerate(Commodity):
print(index,Commodity_list)
user_choice = input('Please enter the commodity number')
if user_choice.isdigit():
user_choice = int(user_choice)
if user_choice < len(Commodity) and user_choice >= 0:
Phone = Commodity[user_choice]
if Phone[1] <= salary:
shopping_cart.append(Phone)
salary -= Phone[1]
print('\033[31mThe %s has joined the shopping cart.Your balance is left %s\033[0m' % (Phone,salary))
else:
print('Your balance is left %s Unable to buy' % salary)
else:
print('The input commodity number does not.Please re-enter')
elif user_choice == 'quit':
print('------------------- shopping list -------------------')
for shopping_cart_list in shopping_cart:
print(shopping_cart_list)
exit()
else:
print('Input error,Please re-enter')
else:
print('The input error program has exited. Please re-enter it')

day3-购物车小程序的更多相关文章

  1. python 购物车小程序

    python 购物车小程序 功能要求:1.启动程序后,输入用户名密码后,让用户输入工资,然后打印商品列表2.允许用户根据商品编号购买商品3.用户选择商品后,检测余额是否够,够就直接扣款,不够就提醒4. ...

  2. [作业] Python入门基础---购物车小程序

    1.购物车小程序: 1.1用户输入工资取60% 1.2打印输出商品菜单 1.3由用户输入数字选择 #__author:Mifen #date: 2018/11/27 # 购物车程序 #把工资作为账户的 ...

  3. python3 购物车小程序,余额写入文件保存

    python3 购物车小程序,余额写入文件保存 #!/usr/bin/env python # -*- coding:utf-8 -*- # Author:Hiuhung Wan goods = ( ...

  4. Day2:购物车小程序

    一.购物车小程序第一版 #!/usr/bin/env python # -*- coding:utf-8 -*- # Author:Hiuhung Wan product_list = [ (&quo ...

  5. python编写购物车小程序

     #练习#程序购物车#启动程序后,让用户输入工资,  然后打印商品列表,允许用户根据商品编号购买商品用户选择商品后 #检测余额是否够,够就直接扣款,不够就提醒可随时退出,退出时,打印已购买商品和余额  ...

  6. Python之路 day2 购物车小程序1

    #Author:ersa ''' 程序:购物车程序 需求: 启动程序后,让用户输入工资,然后打印商品列表 允许用户根据商品编号购买商品 用户选择商品后,检测余额是否够,够就直接扣款,不够就提醒 可随时 ...

  7. python写购物车小程序

    #!/usr/bin/env python3 # -*- coding:utf-8 -*- # @Author: Skyell Wang # @Time : 2018/5/22 15:50 # 基础要 ...

  8. python 练习购物车小程序

    # -*- coding:utf-8 -*- shp = [ ['iphone',5000], ['offee',35], ['shoes',800] ] pric_list = [] e = int ...

  9. 购物车小程序(while循环,列表)

    while True: salary = input("please input your salary:") if salary.isdigit(): salary=int (s ...

  10. python 购物车小程序(列表、循环、条件语句)

    goods = [ ['iphone6s', 5800], ['mac book', 9000], ['coffee', 32], ['python book', 80], ['bicyle', 15 ...

随机推荐

  1. C# 关于utf-8的研究

    前提 如果一不小心把字符转成utf8的格式,但是却产生了乱码.这个时候要么就是寻找其他的转码方式,要么就不想要了,直接过滤吧. 这里说的是直接过滤的办法. 参考链接 https://netvignet ...

  2. c# 多数值区间判断是否有重叠

    /// <summary> /// 金额区间判断帮助类 /// </summary> public static class DecimalRangeHelper { /// ...

  3. [转] docker基础知识之挂载本地目录

    [From] https://blog.csdn.net/huludan/article/details/52641090 https://my.oschina.net/piorcn/blog/324 ...

  4. [转] javascript中的变量和垃圾回收

    [From] http://www.imooc.com/article/4585 基本类型和引用类型 js中的变量虽然不区分类型,但是实际上Ecmascript包含两种类型,基本类型和引用类型. 基本 ...

  5. 从cocos2d-html5中提取出来的,用做前端开发的框架——cc.js

    从cocos2d-html5中提取出来的,用做前端开发的框架——cc.js /************************************************************* ...

  6. 破解myBase试用到期

    请保持你的myBase7是关闭的 1.找到myBase7的安装目录(myBase.exe的目录): 2.右键编辑打开myBase.ini: 3.找到 App.UserLic.FirstUseOn,并在 ...

  7. encoding specified in XML prolog (UTF-8) is different from that specified in page directive (utf-8)

    myeclipse下启动项目后出现错误:encoding specified in XML prolog (UTF-8) is different from that specified in pag ...

  8. AppInventor2笔记

    将视觉化的 块语言 翻译为 Android上的实现 的编译器使用了Kawa语言框架,而Kawa是Scheme编程语言的方言,由Per Bothner开发,并由自由软件基金会发布,它是GNU操作系统的一 ...

  9. mysql 学习之 DDl语句

    mysql 1,登入mysq1: mysql -uroot -p  ---->密码隐藏登入好点 2,mysql操作: 创建数据库:create databases test1; 查看数据库:sh ...

  10. HDU 4460 Friend Chains

    Problem Description For a group of people, there is an idea that everyone is equals to or less than ...