作业-----购物程序
生活随笔
收集整理的這篇文章主要介紹了
作业-----购物程序
小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.
購(gòu)物程序
#_author:Administrator
#date:2019/10/25
#購(gòu)物車(chē)程序
salary=int(input("please input your salary:"))
print("購(gòu)物清單如下")
msg='''
---------購(gòu)物清單---------
1.iphone11 5800
2.mac book 9000
3.coffee 38
4.python book 80
5,bicycle 1200
--------------------------
'''
print(msg)
balance=0
shopping_car=[]
while True:
i = int(input("請(qǐng)輸入你要購(gòu)買(mǎi)的商品編號(hào):"))
list = [0, 5800, 9000, 38, 80, 1200]
object=['0','iphone11','mac book ','coffee ','python book','bicycle']
balance = salary - list[i]
if balance<0:
print("你的余額不足為,%d,請(qǐng)重新選擇:你還需要購(gòu)買(mǎi)東西嗎?[yes/no]"%balance)
say=input("請(qǐng)輸入:")
if say=="yes":
continue
else:
print("歡迎再次光臨")
print("歡迎再次光臨")
print("你的購(gòu)物車(chē)有如下商品:")
print(shopping_car)
break
else:
shopping_car.append(object[i])#將該商品加入域購(gòu)物車(chē)
print("該商品已加入購(gòu)物車(chē),當(dāng)前余額為%d"%balance)
#此處可以一一打印購(gòu)買(mǎi)的商品
print("你還需要購(gòu)買(mǎi)其他商品嗎?[yes/no]")
answer=input("your answer:")
if answer=="yes":
salary=balance
if salary<0:
break
else:
continue
else:
print("歡迎您的光臨")
print("你的購(gòu)物車(chē)有如下商品:")
print(shopping_car)
break
Output:
please input your salary:6000
購(gòu)物清單如下
---------購(gòu)物清單---------
1.iphone11 5800
2.mac book 9000
3.coffee 38
4.python book 80
5,bicycle 1200
--------------------------
請(qǐng)輸入你要購(gòu)買(mǎi)的商品編號(hào):1
該商品已加入購(gòu)物車(chē),當(dāng)前余額為200
你還需要購(gòu)買(mǎi)其他商品嗎?[yes/no]
your answer:yes
請(qǐng)輸入你要購(gòu)買(mǎi)的商品編號(hào):3
該商品已加入購(gòu)物車(chē),當(dāng)前余額為162
你還需要購(gòu)買(mǎi)其他商品嗎?[yes/no]
your answer:no
歡迎您的光臨
你的購(gòu)物車(chē)有如下商品:
['iphone11', 'coffee ']
總結(jié)
以上是生活随笔為你收集整理的作业-----购物程序的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 【caffe-Windows】新层添加—
- 下一篇: (转)第三方支付的盈利模式