最新国产好看的视频,伊人天堂AV在线,国产Aaaaaa视频,蜜臀视频在线观看一区,人妻av色图,密臀久久久精品影片,青青视频免费观看毛片,久草在线观看视,国产三级精品色情在线

Python實戰(zhàn)購物車項目的實現(xiàn)參考

 更新時間:2019年02月20日 15:52:31   作者:村雨1943  
今天小編就為大家分享一篇關于Python實戰(zhàn)購物車項目的實現(xiàn)參考,小編覺得內容挺不錯的,現(xiàn)在分享給大家,具有很好的參考價值,需要的朋友一起跟隨小編來看看吧

購物車程序

要求如下圖

代碼

# --*--coding:utf-8--*--
# Author: 村雨
import pprint
productList = [('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('請輸入整數(shù)')
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?。?!')

結果

總結

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

相關文章

最新評論

美姑县| 武功县| 墨脱县| 辽宁省| 象山县| 景谷| 格尔木市| 北流市| 古丈县| 抚顺市| 莫力| 淮阳县| 建平县| 广河县| 竹溪县| 正蓝旗| 浦北县| 肃南| 三都| 日喀则市| 东光县| 阳朔县| 延津县| 延川县| 阿城市| 留坝县| 阳西县| 新丰县| 三穗县| 且末县| 汉寿县| 若尔盖县| 乳源| 宣化县| 沛县| 丽水市| 吉安县| 镇平县| 襄樊市| 丹东市| 田林县|