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

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

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

購物車程序

要求如下圖

代碼

# --*--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('請(qǐng)輸入整數(shù)')
else:
  salary = int(salary)
  while True:
    for index, item in enumerate(productList):
      print(index + 1, item)
    print('輸入你要買的商品的序號(hào):')
    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('你已經(jīng)購買了' + productList[userWant - 1][0] + ', 你的余額為 ' + str(salary))
        else:
          print('對(duì)不起,你的余額不足!請(qǐng)努力工作吧!')
          print('你當(dāng)前所購買的商品為:')
          for brought in shoppingList:
            pprint.pprint(brought)
          print('你當(dāng)前余額為:', salary)
          exit()
      else:
        print('你輸入的商品序號(hào)有錯(cuò),請(qǐng)重新輸入')
    elif userWant == 'q':
      print('-----------Shopping List----------')
      for brought in shoppingList:
        pprint.pprint(brought)
      print('你的余額為 ', salary)
      exit()
    else:
      print('Invalid input?。?!')

結(jié)果

總結(jié)

以上就是這篇文章的全部?jī)?nèi)容了,希望本文的內(nèi)容對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,謝謝大家對(duì)腳本之家的支持。如果你想了解更多相關(guān)內(nèi)容請(qǐng)查看下面相關(guān)鏈接

相關(guān)文章

最新評(píng)論

鱼台县| 华池县| 乐昌市| 龙江县| 郸城县| 临邑县| 福安市| 仁化县| 会宁县| 芒康县| 厦门市| 榆社县| 惠东县| 西乌珠穆沁旗| 赞皇县| 中西区| 保康县| 明水县| 宜都市| 泰州市| 泰州市| 图木舒克市| 崇礼县| 祁阳县| 文昌市| 新营市| 武夷山市| 南安市| 漠河县| 玛纳斯县| 阿勒泰市| 姜堰市| 汶川县| 临猗县| 德化县| 宁安市| 红桥区| 得荣县| 抚州市| 浙江省| 那曲县|