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. javascript的Astar版 寻路算法

    去年做一个模仿保卫萝卜的塔防游戏的时候,自己写的,游戏框架用的是coco2d-html5 实现原理可以参考 http://www.cnblogs.com/technology/archive/2011 ...

  2. 转 Monitoring Restore/Recovery Progress

    ora-279 是可以忽略的报错 In general, a restore should take approximately the same time as a backup, if not l ...

  3. centos7.3下安装redis3.2 yum安装

    1.进入centos 2.运行:yum install redis 3.安装完成后,选择y,确认 4.进入:cd /etc/;vi redis.conf 将,daemonize 修改为yes,并且添加 ...

  4. HUID 5558 Alice's Classified Message 后缀数组+单调栈+二分

    http://acm.hdu.edu.cn/showproblem.php?pid=5558 对于每个后缀suffix(i),想要在前面i - 1个suffix中找到一个pos,使得LCP最大.这样做 ...

  5. (转)远程SSH连接服务与基本排错

    远程SSH连接服务与基本排错 原文:https://www.cnblogs.com/chensiqiqi/p/6224474.html#top 1.1 为什么要远程连接Linux系统 在实际的工作场景 ...

  6. 分享:JAVA和C# 3DES加密解密

    最近 一个项目.net 要调用JAVA的WEB SERVICE,数据采用3DES加密,涉及到两种语言3DES一致性的问题,下面分享一下,这里的KEY采用Base64编码,便用分发,因为Java的Byt ...

  7. 在Spark shell中基于Alluxio进行wordcount交互式分析

    Spark是一个分布式内存计算框架,可部署在YARN或者MESOS管理的分布式系统中(Fully Distributed),也可以以Pseudo Distributed方式部署在单个机器上面,还可以以 ...

  8. angular的基本要点

    <body ng-app="Myapp"> <div ng-controller="firstcon"> <h1>hello ...

  9. vsftpd配置文件解析

    对vsftpd配置文件详细解答. 1.默认配置: 1>允许匿名用户和本地用户登陆. anonymous_enable=YES local_enable=YES 2>匿名用户使用的登陆名为f ...

  10. TerraBuilder创建地形之去除影像黑边,填充影像

    最近在Skyline项目中使用TerraBuilder创建地形,由于地形比较大,分块下载卫星影像,然后再TerraBuilder中合并,由于合并.图形等等问题,导致创建处理出来的地形中存在严重的缝隙和 ...