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. Codeforces - 570D 离散DFS序 特殊的子树统计 (暴力出奇迹)

    题意:给定一棵树,树上每个节点有对应的字符,多次询问在\(u\)子树的深度为\(d\)的所有节点上的字符任意组合能否凑成一个回文串 把dfs序存储在一个二维线性表中,一个维度记录字符另一个维度记录深度 ...

  2. c# 动态生成继承类并实现序列化特性

    项目来源 App传过来的字段是动态的,希望能保证扩展性,返回时,把所需要的字段与数据融合后再返回过去 数据是第3方来源的,但是序列化后的结果又希望能并列返回 如:App传过来 一个设备Id,客户Id等 ...

  3. [转] Spring Boot特性

    [From] http://blog.javachen.com/2015/03/13/some-spring-boot-features.html 1. SpringApplication Sprin ...

  4. 字典树+map

    Problem Description Carryon最近喜欢上了一些奇奇怪怪的字符,字符都是英文小写字母,但奇怪的是a可能比b小,也可能比b大,好奇怪.与此同时,他拿到了好多的字符串,可是看着很不顺 ...

  5. 【研究】Discuz<3.4任意文件删除漏洞

    这里以Discuz3.2为例 关键字:Powered by Discuz! X3.2 时间有限,就不一一截图了,Discuz所有页面全在Discuz_X3.2_SC_UTF8/upload/目录下 利 ...

  6. Python入门书的读书笔记

    入门书地址 三引号 (""" 或 ''') 来指定多行字符串字符串是不可变的输出小数点后三位 print('{0:.3f}'.format(1 / 3))输出字符串长度为 ...

  7. IOS下去掉input submit圆角和

    在iOS系统下input submit会有圆角,如果添加有背景色,背景色出错,在安卓系统是没有这些问题,可以在input样式加上这段样式 input{ -webkit-appearance: none ...

  8. Java中forEach, 用来遍历数组

    这里的for是Java中forEach, 用来遍历数组的.for(int i : d) 就是遍历int型数组d的 每一次访问数组d的时候读取的数据放入int型的i中.和for(int i=0;i< ...

  9. 线程同步(windows平台):事件

    一:介绍 事件Event实际上是个内核对象,事件分两种状态:激发状态和未激发状态.分两种类型:手动处置事件和自动处置事件.手动处置事件被设置为激发状态后,会唤醒所有等待的线程,一直保持为激发状态,直到 ...

  10. bzoj 5305: [Haoi2018]苹果树

    Description Solution \(n\) 个点的二叉树的方案数是 \(n!\) 证明十分显然:新加入的点占掉了 \(1\) 个位置,新加了 \(2\) 个位置,那么多出来一个位置,所以第 ...