On the sixth day of learning _ cart

Li = [ 
      { ' name ' : ' apple ' , ' . price ' : 10 }, 
      { ' name ' : ' banana ' , ' . price ' : 20 is }, 
      { ' name ' : ' watermelon ' , ' . price ' : 30 } , 
      ] 
shooping_car = {}
 # the goods on shelves 

Print ( 'Welcome fruit shop' ) 
Money = the INPUT ( ' Show me your money ' ) 

IF money.isdigit () and int (Money)> 0:
     the while 1 :
         for i, k in the enumerate (li):
             Print ( ' No. {}, {} commodity price {} ' .format (I, K [ ' name ' ], K [ ' . price ' ])) 
        the Choose = iNPUT ( ' enter the number you want to buy commodities ' )
         IF choose.isdigit () and int (the Choose) < len (Li):
            num = input('请输入你要购买的数量')
            if num.isdigit():
                if int(money) > li[int(choose)]['price'] * int(num):
                   money = int(money) - li[int(choose)]['price'] * int(num)
                   if li[int(choose)]['name'] in shooping_car:
                       shooping_car[li[int(choose)]['name']] = shooping_car[li[int(choose)]['name' ]] + Int (NUM)
                    the else : 
                       shooping_car [Li [int (the Choose)] [ ' name ' ]] = int (NUM)
                    Print ( ' cart goods are {}, your balance is {} ' . format (shooping_car, money))
             the else :
                 Print ( ' home to get money to go ' )
                 BREAK 

        the else :
             Print ( ' say the number is ' )

 

Guess you like

Origin www.cnblogs.com/wan520/p/10962351.html