Python3中实现简单的购物车程序
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中实现简单的购物车程序的更多相关文章
- Python3学习之路~2.2 简单的购物车程序
程序:购物车程序 需求:启动程序后,让用户输入工资,然后打印商品列表允许用户根据商品编号购买商品用户选择商品后,检测余额是否够,够就直接扣款,不够就提醒 可随时退出,退出时,打印已购买商品和余额 代码 ...
- 利用JSP编程技术实现一个简单的购物车程序
实验二 JSP编程 一.实验目的1. 掌握JSP指令的使用方法:2. 掌握JSP动作的使用方法:3. 掌握JSP内置对象的使用方法:4. 掌握JavaBean的编程技术及使用方法:5. 掌握JSP ...
- python基础代码(猜年龄、从最内层跳出多层循环、简单的购物车程序)
1.猜年龄 , 可以让用户最多猜三次! age = 55 i=0 while i<3: user_guess = int (input ("input your guess:" ...
- Python3.5 Day2作业:购物车程序
需求: 1. 启动程序后,用户通过账号密码登录,然后打印商品列表. 2. 允许用户根据商品编号购买商品. 3. 用户选择商品后,检测余额是否足够,够就直接扣款,不够就提醒充值. 4. 可随时退出,退出 ...
- 工作中一个简单的shell程序
下面是工作中用到的链接数据库的shell程序. #!/bin/bash ] ; then echo "prase is wrong ,please check first" exi ...
- python中最简单的多进程程序
学着.. #!/usr/bin/env python # -*- coding: utf-8 -*- # Spawn a Process: Chapter 3: Process Based Paral ...
- python3 写一个简单的websocket程序(转)
原贴:https://segmentfault.com/q/1010000009284816?_ea=1883181 也是找了好久 #! /usr/bin/env python # -*- codin ...
- 使用MongoDB和JSP实现一个简单的购物车系统
目录 1 问题描述 2 解决方案 2.1 实现功能 2.2 最终运行效果图 2.3 系统功能框架示意图 2.4 有关MongoDB简介及系统环境配置 2.5 核心功能代码讲解 ...
- python3中sys.argv[]小记
1.python3中sys.argv[]用于传递程序外部的参数,外部一般指命令行输入的参数,argv[]所传递的参数实质上是一个列表,其第一个元素为程序本身. 2. sys.argv[] #传入的参数 ...
随机推荐
- 用phpinfo( )打印出来的php版本和在服务器上用php -v打印出来的版本不同的原因
php -v 是linux系统的php版本,而phpinfo里显示的是WEB Server中配置的版本.说简单点,你的系统中有两个php版本. 如果您阅读过此文章有所收获,请为我顶一个,如果文章中有错 ...
- java常用的空对象 null
- Java-API-Package:org.springframework.web.bind.annotation
ylbtech-Java-API-Package:org.springframework.web.bind.annotation 1.返回顶部 1. @NonNullApi @NonNullField ...
- Exception in thread "main" javax.validation.ValidationException: Unable to find a default provider
Exception in thread "main" javax.validation.ValidationException: Unable to find a default ...
- mybatis---demo1--(单表增删改查)----bai
实体类: package com.etc.entity; public class News { private int id; private String title; private Strin ...
- Git学习笔记(三)远程库(GitHub)协同开发,fork和忽略特殊文件
远程库 远程库,通俗的讲就是不再本地的git仓库!他的工作方式和我们本地的一样,但是要使用他就需要先建立连接! 远程库有两种,一个是自己搭建的git服务器:另一种就是使用GitHub,这个网站就是提供 ...
- Python函数(一)-return返回值
定义一个函数可以在最后加上return返回值,方便查看函数是否运行完成和返回函数的值 # -*- coding:utf-8 -*- __author__ = "MuT6 Sch01aR&qu ...
- 2015.3.2 VC++6制作非MFC dll以及VS2005、VS2010调用
1.在VC6中新建工程,选择Win32 Dynamic-Link Libary,输入dll名称如 DLL2015 2.在类型选择中,选择第2项 A Simple Dll project OK 3.随后 ...
- H264中的SPS、PPS提取与作用<转>
牛逼的视频会议网站:http://wmnmtm.blog.163.com/blog/#m=0 ++++++++++++++++++++++++++++++++++++++++++++++++++++ ...
- mysql join查询的on 与 where 的不同点
on总数以left join的左表为准,where会过滤掉,不符合where条件的数据