标签:
作业:购物商场
1、商品展示,价格
2、银行卡余额
3、付账
程序流程图如下:

代码如下:
ShopDisplay = {‘clothes1‘:‘498‘,‘jeans‘:‘128‘,‘shoes‘:‘289‘,‘hat‘:‘99‘,‘clothes2‘:‘599‘}
print(ShopDisplay)
ShoppingCartPrice = [] #购物车商品价格
ShoppingCart = {} #购物车
while True:
thing = input("You want to buy :")
price = ShopDisplay[‘%s‘ %thing]
ShoppingCart.update({ ‘%s‘ %thing:‘%s‘ %price })
ShoppingCartPrice.append(‘%s‘ % price)
answer = input("Do you want to continue buy something else?Please say yes or no:\n")
if answer == ‘yes‘:
continue
else:
break
def shit(): #判断余额是否大于所要买的商品
sum = 0
TotalMoney = 1000
for i in ShoppingCartPrice:
sum = sum + int(i)
TotalMoney = TotalMoney - sum
if TotalMoney > 0:
a = input("Do you really want to buy tins ?Please enter yes or no !\n")
if a == ‘yes‘:
print("Successful,wish you a happy shopping!\n")
else:
print("Thanks you for come to my ")
exit()
else:
print("Sorry,you have not enough money!Please remove somethings!\n")
sum = 0
TotalMoney = 1000
for i in ShoppingCartPrice:
sum = sum + int(i)
TotalMoney = TotalMoney - sum
if TotalMoney > 0 :
a = input("Do you really want to buy tins ?Please enter yes or no !\n")
if a == ‘yes‘:
print("Successful,wish you a happy shopping!\n")
exit()
else :
exit()
else :
print("Sorry,you have not enough money!Please remove somethings!\n")
while True:
print("Your shopping cart have this thing:\n")
print(ShoppingCart)
print("If you don‘t want to del,please enter ‘.‘\n")
del_thing = input("Please input the goods that you don‘t want to buy:\n")
if del_thing == ‘.‘:
break
s = ShoppingCart[‘%s‘ % del_thing]
ShoppingCart.pop(‘%s‘ % del_thing)
ShoppingCartPrice.remove(s) #删除不买的东西
shit()
代码很简陋,作业功能基本都实现了,将就着看吧。。。。日后再来优化
标签:
原文地址:http://www.cnblogs.com/learnC/p/5859678.html