python实现简单的循环购物车小功能

# -*- coding: utf-8 -*-
__author__ = 'hujianli' shopping = [
("iphone6s", 5000),
("book python", 81),
("iwach", 3200),
("电视机", 2200)
] def zero(name):
if len(name) == 0:
print("\033[31;1m您的输入不能为空,清重新输入~~\033[0m")
exit()
else:
return True def crre(name):
if int(name) not in range(len(shopping)):
print("\033[31;1m您输入了错误的序列号,请重新输入~~\033[0m")
exit()
else:
return True gongzi = input("请输入您目前的工资:")
if not gongzi.isdigit():
crre()
elif len(gongzi) == 0:
zero()
else:
gongzi = int(gongzi)
print("=========================================")
print("===要购买的列表清单如下: ")
for i,j in enumerate(shopping):
print(i, j[0], j[1]) shopping_cart = []
while True:
choice = input("请输入你要购买的商品,输入q或者exit退出选择回到购物车列表: ")
if choice.isdigit():
zero(choice)
crre(choice)
choice = int(choice)
goods = shopping[choice]
if gongzi < int(goods[1]):
gongzi -= goods[1]
print("===您的工资余额不够使用了,还差\033[1;31m{}\033[0m请努力挣钱===.".format(abs(gongzi)))
else:
print("您选购的商品:\033[1;32m %s \033[0m 已经加入到购物车.." % (goods[0]))
shopping_cart.append(goods)
gongzi -= goods[1]
print("您的工资余额还剩下:\033[30;42m %s\033[0m"% (gongzi))
elif (choice == "q") or (choice == "exit"):
break print('\033[30;42m你已购商品列表\033[0m'.center(42,'-'))
for i,j in enumerate(shopping_cart):
print("\033[1;32m" + str(i+1) + " " + str(j[0]) + " " + str(j[1]) + "\033[0m")

python实现简单的循环购物车小功能的更多相关文章

  1. python实例2-写一个爬虫下载小功能

    主要是通过url,和re两个模块对一个网页的固定图片进行模糊匹配后下载下来. #! /usr/bin/python import re import urllib def gethtml(url): ...

  2. python实现简单的一个刷票点赞功能

    投票网址:http://best.zhaopin.com/?sid=121128100&site=sou 在以上网址中找到"XXX技术有限公司",通过Python进行刷票. ...

  3. 用python实现简单的计算器(加减乘除小括号等)

    需求:实现能计算类似 1 - 2 * ( (60-30 +(-40/5) * (9-2*5/3 + 7 /3*99/4*2998 +10 * 568/14 )) - (-4*3)/ (16-3*2) ...

  4. Python简单的购物车小代码

    # -*- coding: utf-8 -*- # @Time : 2018-05-31 14:56 # @Author : 超人 # @Email : huxiaojiu111@gmail.com ...

  5. python 购物车小程序

    python 购物车小程序 功能要求:1.启动程序后,输入用户名密码后,让用户输入工资,然后打印商品列表2.允许用户根据商品编号购买商品3.用户选择商品后,检测余额是否够,够就直接扣款,不够就提醒4. ...

  6. Django开发简单采集用户浏览器信息的小功能

    Django开发简单采集用户浏览器信息的小功能 Centos环境准备 yum install –y python-pip export http_proxy=http://10.11.0.148:80 ...

  7. [Python]Python 使用 for 循环的小例子

    [Python]Python 使用 for 循环的小例子: In [7]: for i in range(5): ...: print "xxxx" ...: print &quo ...

  8. python实现简单的聊天小程序

    概要 这是一个使用python实现一个简单的聊天室的功能,里面包含群聊,私聊两种聊天方式.实现的方式是使用套接字编程的一个使用TCP协议 c/s结构的聊天室 实现思路 x01 服务端的建立 首先,在服 ...

  9. [作业] Python入门基础---购物车小程序

    1.购物车小程序: 1.1用户输入工资取60% 1.2打印输出商品菜单 1.3由用户输入数字选择 #__author:Mifen #date: 2018/11/27 # 购物车程序 #把工资作为账户的 ...

随机推荐

  1. JSP----获取表单参数

    在页面中可大量使用 request 对象来获取表单域的值,获取表单域的值有如下两个 方法. • String getParamete(String para mN ame): 获取表单域的值. • S ...

  2. 【AngularJS中的自定义服务service VS factory VS provider】---它们的区别,你知道么?

    在介绍AngularJS自定义服务之前,我们先来了解一下AngularJS~ 学过HTML的人都知道,HTML是一门很好的伪静态文本展示设计的声明式语言,但是,要构建WEB应用的话它就显得乏力了. 而 ...

  3. html学习笔记 - 列表

    <!-- 无序列表 --> <ul type = square> <li><a href="https://www.baidu.com"& ...

  4. 网站权限管理 之 角(jue)色管理

    公司或网站的正常运行,离不开管理员对各个员工的合理分配,那先看看权限管理中的角色管理好了: 要更改用户的角色,那么先来理一下思路: (1)用户现在是什么角色? (2)用户将要成为什么角色? (3)怎样 ...

  5. What does a Bayes factor feel like?(转)

    A Bayes factor (BF) is a statistical index that quantifies the evidence for a hypothesis, compared t ...

  6. cuda学习3-共享内存和同步

    为什么要使用共享内存呢,因为共享内存的访问速度快.这是首先要明确的,下面详细研究. cuda程序中的内存使用分为主机内存(host memory) 和 设备内存(device memory),我们在这 ...

  7. 总结常见的ES6新语法特性。

    前言 ES6是即将到来的新版本JavaScript语言的标准,他给我们带来了更"甜"的语法糖(一种语法,使得语言更容易理解和更具有可读性,也让我们编写代码更加简单快捷),如箭头函数 ...

  8. Redis中的数据结构与常用命令

    开发系统:Ubuntu 17.04Redis驱动:StackExchange.Redis 1.2.3Redis版本:3.2.1开发平台:.NET Core 对于Redis的介绍这里只写一句:Redis ...

  9. WireShark网络分析就这么简单 读后感

    京东618活动,满200减100,果断入手了这本经典的 WireShark教程

  10. orcle :Could not initialize "D:\app\Administrator\product\11.2.0\dbhome_1\bin\oci.dll" Make sure you have the 32 bits Oracle Client installed.

    服务器重启后,数据库登录信息为空 错误信息: ---------------------------(Not logged on) - PL/SQL Developer---------------- ...