python 的 购物小程序
生活随笔
收集整理的這篇文章主要介紹了
python 的 购物小程序
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
1 money = input('請輸入您的工資:')
2 shop = [("iphone",5800),("ipod",3000),("book",210),("Archer python",80)]
3 while not money.isdigit():
4 print("請正確輸入整數",end=':')
5 money = input()
6 money = int(money)
7 while True:
8 print("商品詳情".center(50,'-'))
9 for i in range(len(shop)):
10 print("%d. %s $%s".center(50,' ') % (i,shop[i][0],shop[i][1]))
11 print("請輸入你要購買的商品序號,(退出請按'q'):",end='')
12 num = input()
13 while not( num == 'q' or num.isdigit() and int(num) < len(shop) and int(num) >= 0 ):
14 print("請正確輸入商品序號:",end='')
15 num = input()
16 if num == 'q':
17 break
18 num = int(num)
19 if money >= int(shop[num][1]):
20 money -= int(shop[num][1])
21 print("您購買了%s 價格為%d --您還有余額為\033[31;1m$%d\033[1m" % (shop[num][0],shop[num][1],money))
22 elif money <= int(shop[num][1]):
23 print("您當前余額不足,剩余余額為:\033[31;1m$%d\033[1m"%(money)) shopping
?
轉載于:https://www.cnblogs.com/guiltyWay/p/9682323.html
總結
以上是生活随笔為你收集整理的python 的 购物小程序的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 数据库系列之mysql 自定义函数fun
- 下一篇: 将Python文件打包为exe文件,并在