product_list = [
('iphone',5800),
('imac',15800),
('watch',9800),
('cloth',550),
('coffe latee',35),
('body call',200),
]
shopping_list = []
salary = input('please input your salary:').strip()
if salary.isdigit():
salary = int(salary)
while True:
for index,item in enumerate(product_list):
print(index,item)
user_choice = input('please input your choice'.center(50,'*')).strip()
if user_choice.isdigit():
user_choice = int(user_choice)
if 0 <= user_choice < len(product_list):
buy_item = product_list[user_choice]
if salary >= buy_item[1]:
shopping_list.append(buy_item)
salary -= buy_item[1]
print('you have put the \033[32;1m"%s" \033[0min your cast,your balance is\033[31;1m %d\033[0m'%(buy_item[0],salary))
else:
print('\033[41;1mfuck off!!! you can`t afford it!!! your balance is %s !!!\033[0m'%(salary))
else:
print('product code [%s] is not exist!!!'%user_choice)
elif user_choice == 'q' or user_choice == 'quit':
print('you have buyed:'.center(50,'-'))
print(shopping_list)
exit()
else:
print('Invalid choice!!!')

  

Python3中实现简单的购物车程序的更多相关文章

  1. Python3学习之路~2.2 简单的购物车程序

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

  2. 利用JSP编程技术实现一个简单的购物车程序

    实验二   JSP编程 一.实验目的1. 掌握JSP指令的使用方法:2. 掌握JSP动作的使用方法:3. 掌握JSP内置对象的使用方法:4. 掌握JavaBean的编程技术及使用方法:5. 掌握JSP ...

  3. python基础代码(猜年龄、从最内层跳出多层循环、简单的购物车程序)

    1.猜年龄 , 可以让用户最多猜三次! age = 55 i=0 while i<3: user_guess = int (input ("input your guess:" ...

  4. Python3.5 Day2作业:购物车程序

    需求: 1. 启动程序后,用户通过账号密码登录,然后打印商品列表. 2. 允许用户根据商品编号购买商品. 3. 用户选择商品后,检测余额是否足够,够就直接扣款,不够就提醒充值. 4. 可随时退出,退出 ...

  5. 工作中一个简单的shell程序

    下面是工作中用到的链接数据库的shell程序. #!/bin/bash ] ; then echo "prase is wrong ,please check first" exi ...

  6. python中最简单的多进程程序

    学着.. #!/usr/bin/env python # -*- coding: utf-8 -*- # Spawn a Process: Chapter 3: Process Based Paral ...

  7. python3 写一个简单的websocket程序(转)

    原贴:https://segmentfault.com/q/1010000009284816?_ea=1883181 也是找了好久 #! /usr/bin/env python # -*- codin ...

  8. 使用MongoDB和JSP实现一个简单的购物车系统

    目录 1 问题描述  2 解决方案  2.1  实现功能  2.2  最终运行效果图  2.3  系统功能框架示意图  2.4  有关MongoDB简介及系统环境配置  2.5  核心功能代码讲解  ...

  9. python3中sys.argv[]小记

    1.python3中sys.argv[]用于传递程序外部的参数,外部一般指命令行输入的参数,argv[]所传递的参数实质上是一个列表,其第一个元素为程序本身. 2. sys.argv[] #传入的参数 ...

随机推荐

  1. Linux基础命令-echo

    echo命令 功能:显示字符 (末尾自带换行功能) 语法:echo [-neE][字符串] 说明:echo会将输入的字符串送往标准输出.输出的字符串间以空白字符隔开, 并在最后加上换行号 -n 不在字 ...

  2. 自定义mysql函数时报错,[Err] 1418 - This function has none of DETERMINISTIC......

    今天在我执行自定义mysql函数的SQL时发生了错误,SQL如下: /** 自定义mysql函数 getChildList */delimiter //CREATE FUNCTION `pengwif ...

  3. Oracle 11g R2(11.2.0.4) RAC 数据文件路径错误解决--ORA-01157 ORA-01110: 数据文件

    Oracle 11g R2(11.2.0.1) RAC  数据文件路径错误解决--ORA-01157 ORA-01110: 数据文件 oracle 11g R2(11.2.0.4) rac--scan ...

  4. 【转】Rails中Bootstrap的安装和使用

     转自:http://blog.csdn.net/lissdy/article/details/9195651   眼看着前端攻城师们都开始使用Bootstrap创作网页,于是也想学着在最近正在学习的 ...

  5. mybatis 动态sql语句(1)

    mybatis 的动态sql语句是基于OGNL表达式的.可以方便的在 sql 语句中实现某些逻辑. 总体说来mybatis 动态SQL 语句主要有以下几类: 1. if 语句 (简单的条件判断) 2. ...

  6. 生产者与消费者--demo1---bai

    import java.util.ArrayList; import java.util.List; import java.util.Random; //自定义类,描述仓库 public class ...

  7. laravel4 composer报错 d11wtq/boris v1.0.10 requires ext-pcntl

    laravel4 composer报错 d11wtq/boris v1.0.10 requires ext-pcntl laravel 4.2 用composer 安装任何包都会报这个错,通过谷歌找到 ...

  8. springJunit测试

    ; m.setModelType(s); m.setModelUrlType(s); modelService.create(m); } }   来源: http://enki-ding-yeah-n ...

  9. 使用Get进行Http通信

    --------------siwuxie095 有道翻译官网:http://fanyi.youdao.com/ 找到官网页面下方的 有道翻译API,选择 调用数据接口,申请一个 key (申请内容可 ...

  10. IFC数据模型在三维引擎中模拟