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. ZOJ Monthly, January 2019 I Little Sub and Isomorphism Sequences(set 妙用) ZOJ4089

    写这篇博客来证明自己的愚蠢 ...Orz  飞机 题意:给定你个数组,以及一些单点修改,以及询问,每次询问需要求得,最长的字串长度,它在其他位置存在同构 题解:经过一些奇思妙想后 ,你可以发现问题是传 ...

  2. BZOJ - 3224 可持久化Treap 树形操作

    这个题目去年就做过了,这次稍微改了一下 都是基础操作 #include<iostream> #include<algorithm> #include<cstdio> ...

  3. node.js知识点提取

    javascript是脚本语言,脚本语言都需要一个解析器才能运行.

  4. [转] Kubernetes集群安装文档-v1.6版本

    [From] https://www.kubernetes.org.cn/1870.html http://jimmysong.io/kubernetes-handbook

  5. [转] 用Python建立最简单的web服务器

    [From] http://www.cnblogs.com/xuxn/archive/2011/02/14/build-simple-web-server-with-python.html 利用Pyt ...

  6. js面向切面编程

    Function.prototype.before=function(func){ var _self=this; return function(){  if(func.apply(this,arg ...

  7. Yii2 执行Save()方法失败,却没有错误信息

    一般用$model->errors 就能查看到更新失败的原因,但是这次却什么错误信息都没有,最后发现是因为在模型类中定义了一个方法 public function beforeSave($ins ...

  8. android点击桌面App图标activity启动流程

    1.点击桌面App图标,Launcher进程采用Binder IPC向system_server进程发起startActivity请求:2.system_server进程接收到请求后,向zygote进 ...

  9. 【温故知新】c#抽象类abstract与接口interface

    1.什么是抽象类 先来看MSDN对抽象类描述: 抽象类是一些留有部分或全部成员未实现的类,以便可以由派生类来提供实现. 在面向对象的编程中,抽象类用作层次结构的基类,并表示不同对象类型组的通用功能.  ...

  10. java io 学习笔记(三) 字符流读写

    1.字符流读取 字符流读取的所有类都是从Reader这个超类继承的,都是用于读取字符的,这些类分别是InputSteamReader(从字符流读取).FileReader(继承与InputStream ...