#shopping code
#shopping.py
#导入登录模块
import login
# shop car beginning
salary = input("请输入工资:\t")
###判断输入工资是否为整型###
if salary.isdigit():
salary = int(salary)
else:
print ("salary not digit")
exit()
###打印一句牛逼的话####
welcome_msg = 'welcome to our shoping mall'
print(welcome_msg.center(50, '-'))
###商品列表####
shopcar = [
('Iphone', 5888),
('Mac Air', 8000),
('XiaoMi', 19.9),
('coffee', 30),
('Tesla', 8200),
('Bike', 700),
('Cloth', 200)
]
for i in enumerate(shopcar):
index = i[0]
product = i[1][0]
p_salary = i[1][1] print (index, product, p_salary) exit_msg = '你可以输入e或者q退出,啦啦啦'
print(exit_msg.center(50, '-')) while True:
num = input("\033[5;30;43mplease print bianhao:\033[0m\t")
if num.isdigit():
num = int(num)
###判断输入编号不能大于7###
if num > 7:
print ("输入错误,没有此编号")
continue
##输入编号购买商品###
num = input("请输入商品编号:\t")
price = shopcar[num][1]
price_p = shopcar[num][0]
if salary > price:
salary -= price
print ("购买成功,余额为", salary)
print ("购买的商品为:", price_p)
else:
print ("余额不足,请及时充值")
print ("余额为", salary)
continue
##exit shoping##
elif num.isalpha():
num = str(num)
if num == 'e' or num == 'q':
print ("余额为", salary)
bye_msg = 'next to meet you,see you'
print(bye_msg.center(50, '-'))
break
# if price_p():
# print ("余额为", salary)
# exit()
# else:
# print ("购买成功,余额为", salary)
# print ("购买的商品为:", price_p)
# bye_msg = 'next to meet you,see you'
# print(bye_msg.center(50, '-'))

python shopping incomplete code的更多相关文章

  1. Converting Python Virtual Machine Code to C

    Converting Python Virtual Machine Code to C

  2. Python on VS Code

    install python extension Press F1, and input "ext install python". Then the icon at the le ...

  3. python 调用 C++ code

    本文以实例code讲解python 调用 C++的方法. 1. 如果没有参数传递从python传递至C++,python调用C++的最简单方法是将函数声明为C可用函数,然后作为C code被pytho ...

  4. Python “ValueError: incomplete format” print(“a%” % ”)

    解决python打印%号和%format输出问题 >>> print('%s' %'1') 1 >>> print('%s%' %'1') Traceback (m ...

  5. Pycharm创建Django项目显示python non-zero exit code(1)错误

    好久时间没有做Django的项目了,今天创建项目竟然报Non-zero exit code(1)错误 查明原因是因为pip不是最新版本,需要执行以下命令:python -m pip install - ...

  6. python en(de)code

    python爬虫 代码写挺长的,也是边学边写,但一直搞不清楚python的encode(编码)和decode(解码).以下是我的探究之路. 一.当然先看官方文档 地址如下 里面提到encode函数'R ...

  7. python单线程爬虫code

    广度优先算法: # -*- coding: utf-8 -*- import urllib import urllib.request from bs4 import BeautifulSoup im ...

  8. python——shopping car

    # _Author:huang# date: 2017/11/26 # 简单的购物车程序money = input("money:") product_list = [ (&quo ...

  9. facebook视频上传python 返回错误code:100,'type':OAuthException

    首先重新获取访问口令token: https://developers.facebook.com/tools/debug/accesstoken/?q=EAAYDuzyd3eYBAK9lZCErZBl ...

随机推荐

  1. form表单提交到Controller之后空值变成逗号

    首先这个错误不是我遇到的,是别人遇到来找我给帮忙调试的(我不会犯这种错误!!!) 错误非常神奇,前端页面的form表单是空的啥都没填,提交到后台之后(后台用@ModelAttribute实体类接受的) ...

  2. Python练习 | Web本质Socket

    #--------------------------------客户端-------------------------------------- # 导入socket库 import socket ...

  3. python在读取配置文件存入列表中,去掉回车符号

    self.receiver = map(lambda x: x.strip(), receiver_list) # 去掉list中的回车符号

  4. 封装你的协程Unity TaskManager

    unity5提供了协程,不过用起来很蛋疼,当然如果是unity2017 你就可以用async await了 提供一个TaskManager来封装协程(github  https://github.co ...

  5. SpringMVC的参数绑定

    一.@RequestMapping注解说明   通过@RequestMapping注解可以定义不同的处理器映射规则. URL路径映射 @RequestMapping(value="/item ...

  6. 自定义控件如何给特殊类型的属性添加默认值 z(转)

    自定义控件如何给特殊类型的属性添加默认值 z 定义控件如何给特殊类型的属性添加默认值了,附自定义GroupBox一枚 标题有点那啥,但确实能表达我掌握此法后的心情. 写自定义控件时往往会有一个需求,就 ...

  7. zato server启动后自动关闭问题解决

    症状 zato start server 启动server后,过一会server自动关闭了 解决 查看日志 UnicodeDecodeError: 'ascii' codec can't decode ...

  8. javah找不到类文件

    这样即可,在src目录下寻找类,类要写全,即包名.类名

  9. Win7 开机启动

    1.注册表里面写代码,设置程序以开机启动; 但这样会需要管理员权限,添加程序以管理员权限启动后,又无法直接进入到软件启动界面,UAC控制 代码一: /// <summary> /// 设置 ...

  10. webpack的学习感悟

    https://github.com/webpack/webpack    webpack gethub地址. http://webpack.github.io/   webpack 官网 前言 we ...