#! /usr/bin/env python
# -*- coding: utf-8 -*-
# __author__ = "Deakin"
# Email: [email protected]
# Date: 2018/1/2
#程序:购物车程序
#需求:
#启动程序后,让用户输入工资,然后打印商品列表
#允许用户根据商品编号购买商品
#用户选择商品后,检测余额是否够,够就直接扣款,不够就提醒
#可随时退出,退出时,打印已购买商品和余额
product_list=[
("iphone",8000),
("computer",6000),
("car",30000),
("coffee",30),
("watch",500),
("book",80),
]
shopping_list=[]
salary=input("please key in your salary:")
if salary.isdigit():
salary=int(salary)
while True:
#for item in product_list:
#print(product_list.index(item),item)
#break
for index,item in enumerate(product_list):
print(index,item)
print("选择要购买的商品编号,按q退出")
user_choice=input("选择要购买的商品:")
if user_choice.isdigit():
user_choice=int(user_choice)
if user_choice<len(product_list) and user_choice>=0:
p_item=product_list[user_choice]
if p_item[1]<=salary:#买得起
shopping_list.append(p_item)
salary-=p_item[1]
print("added %s into shopping cart,your current balance is \033[31;1m%s\033[0m"%(p_item,salary))
else:#买不起
print("\033[41;1m穷逼,你的余额只有%s了,还不赶紧充钱\033[0m"%(salary))
else:
print("the product is not exist")
elif user_choice==‘q‘:
print("-------shopping list-------")
for p in shopping_list:
print(p)
print("your balance is :",salary)
exit()
else:
print("invalid opation")
instance 1:shopping cart
Posted deakin-du
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了instance 1:shopping cart相关的知识,希望对你有一定的参考价值。
以上是关于instance 1:shopping cart的主要内容,如果未能解决你的问题,请参考以下文章
tomcat启动慢,Creation of SecureRandom instance for session ID generation using [SHA1PRNG]took [xx] ms(代
Unity Error executing result=instance->m_Sound->lock()An invalid parameter was passed to this func(代
解决Linux Tomcat启动慢--Creation of SecureRandom instance for session ID generation using [SHA1PRNG] to(代