国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 編程 > Python > 正文

Python實戰購物車項目的實現參考

2020-02-16 01:15:50
字體:
來源:轉載
供稿:網友

購物車程序

要求如下圖

代碼

# --*--coding:utf-8--*--# Author: 村雨import pprintproductList = [('Iphone 8', 10000),        ('GTX2080', 8000),        ('Z7KP7-GT', 6000),        ('Mac pro', 15000),        ('Honor 10', 2800),        ('Iphone XR', 12000),        ('Mi 8', 2999)        ]shoppingList = []print('輸入你的工資:')salary = input()if not salary.isdigit():  print('請輸入整數')else:  salary = int(salary)  while True:    for index, item in enumerate(productList):      print(index + 1, item)    print('輸入你要買的商品的序號:')    userWant = input()    if userWant.isdigit():      userWant = int(userWant)      if userWant <= len(productList) and userWant > 0:        print('你要購買的是:', productList[userWant - 1][0])        if salary >= productList[userWant - 1][1]:          shoppingList.append(productList[userWant - 1][0])          salary -= productList[userWant - 1][1]          print('你已經購買了' + productList[userWant - 1][0] + ', 你的余額為 ' + str(salary))        else:          print('對不起,你的余額不足!請努力工作吧!')          print('你當前所購買的商品為:')          for brought in shoppingList:            pprint.pprint(brought)          print('你當前余額為:', salary)          exit()      else:        print('你輸入的商品序號有錯,請重新輸入')    elif userWant == 'q':      print('-----------Shopping List----------')      for brought in shoppingList:        pprint.pprint(brought)      print('你的余額為 ', salary)      exit()    else:      print('Invalid input!!!')

結果

總結

以上就是這篇文章的全部內容了,希望本文的內容對大家的學習或者工作具有一定的參考學習價值,謝謝大家對武林站長站的支持。如果你想了解更多相關內容請查看下面相關鏈接

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 锦屏县| 霍邱县| 长白| 洞头县| 阿勒泰市| 巴东县| 阳东县| 高雄县| 尚义县| 土默特右旗| 白山市| 饶阳县| 威海市| 广灵县| 合作市| 东阳市| 翁源县| 周至县| 临潭县| 阿合奇县| 长宁区| 苏州市| 天津市| 峨边| 卢龙县| 邢台市| 云龙县| 青川县| 尤溪县| 和林格尔县| 柏乡县| 通江县| 炉霍县| 东平县| 昭觉县| 六枝特区| 峨边| 息烽县| 安仁县| 鲁山县| 泗洪县|