乡下人产国偷v产偷v自拍,国产午夜片在线观看,婷婷成人亚洲综合国产麻豆,久久综合给合久久狠狠狠9

  • <output id="e9wm2"></output>
    <s id="e9wm2"><nobr id="e9wm2"><ins id="e9wm2"></ins></nobr></s>

    • 分享

      Python No.13 之練習(xí)(購物車)語句while、for、list等

       頭號碼甲 2021-06-24
      # !/usr/bin/env python
      # -*- coding:utf-8 -*-
      # Author:Hugolinhj

      #ps:字符編碼是UTF-8,單獨(dú)DOS運(yùn)行需要刪除字體改變代碼。


      #練習(xí),定義商品清單,客戶輸入余額(整數(shù)),選擇商品后,扣除金額。
      product_list = [
      ('iphone',5800),
      ('Mac_pro',9800),
      ('bike',800),
      ('coffee',30),
      ('Watch',10600),
      ('MingYW',10000),
      ]
      shopping=[]
      #定義兩個變量,product_list:商品清單。shopping:購物清單。
      salary = input('Input your Salary:')
      #定義變量salary,用戶金額。
      count = 3
      #定義變量count,為計算輸入多次錯誤字符后,退出。
      while count >0:
      if salary.isdigit():
      #判斷字符是否為整數(shù),或字符串可否轉(zhuǎn)整數(shù)。
      salary = int(salary)
      #轉(zhuǎn)int整數(shù)類型
      while True:
      for item in enumerate(product_list): #依次循環(huán)商品清單
      #enumerate()顯示列表的下標(biāo)
      #上句等于 for item in product_list:
      #print (product_list.index(item),item)
      print(item)
      user_choice = input('需要的商品>>>')
      #定義變量user_choice為用戶選擇的序號'下標(biāo)'.
      if user_choice.isdigit():
      user_choice = int(user_choice)
      if user_choice < len(product_list) and user_choice >=0:
      #len(product_list)檢查product_list的長度為6。判斷,比較。
      p_item = product_list[user_choice]
      #定義變量p_item為所選商品。
      if p_item[1] <= salary:
      #比較p_item下標(biāo)1的數(shù)值,與salary用戶余額
      shopping.append(p_item)
      #添加商品入變量p_item入shopping列表中
      salary -=p_item[1]
      #余額減p_item下標(biāo)1的數(shù)值
      print('添加 %s 加入購物車,你得余額為 \033[31:1m%s\033[0m'%(p_item,salary))

      # \033[31:1m'%s’\033[0m '%s’改字體顏色為紅色、加粗。
      # \033[41:1m'%s’\033[0m '%s’改字體顏色為背景紅色、加粗。
      # \033[33:1m'%s’\033[0m '%s’改字體顏色為背景黃色、加粗。

      else:print("\033[31:1m你的余額不足,請重新輸入??!或者輸入q\033[0m")
      else:print('你輸入的有誤!請重新輸入。請按'q’退出!')
      elif user_choice == 'q':
      if len(shopping) == 0:
      print ('你未購買商品!謝謝光臨!')
      print('你的余額:%s'%(salary))
      exit ()
      else:
      print('你購買商品如下:')
      for p in shopping:
      print(p)
      print('你的余額:%s'%(salary))
      exit()
      else:
      print('你輸入的有誤!請重新輸入,')
      else:break
      elif salary=='q':
      print('感謝你得使用!')
      exit()
      else:
      print('你輸入的有誤!請重新輸入或者輸入"q"退出!')
      print('你剩余機(jī)會還有:',count,'次')
      salary=input('請重新輸入>>>')
      count -= 1
      #巡檢次數(shù)減1
      else:print('感謝你得使用!')


      shopping=
      Are you want?
      iphone = 5800
      mac_pro = 12000
      coffee = 30
      bike = 800

      for i in shopping:
      print(i)
      '''

        本站是提供個人知識管理的網(wǎng)絡(luò)存儲空間,所有內(nèi)容均由用戶發(fā)布,不代表本站觀點(diǎn)。請注意甄別內(nèi)容中的聯(lián)系方式、誘導(dǎo)購買等信息,謹(jǐn)防詐騙。如發(fā)現(xiàn)有害或侵權(quán)內(nèi)容,請點(diǎn)擊一鍵舉報。
        轉(zhuǎn)藏 分享 獻(xiàn)花(0

        0條評論

        發(fā)表

        請遵守用戶 評論公約

        類似文章 更多