1 #!/usr/bin/python2 #Coding=utf-83 ImportMultiprocessing4 5Str="Welcome to the rookie shopping system! "6 PrintStr.center (80)7Money=input ("Please enter your budget:",)8 defShow ():9 Print " "This shop offers the following products:Ten Kindle One mac A Apple $450 - mp3 - ThinkPad $800" " the Show () -d={'Kindle': 300,'mac': 500,'mp3': 30,'ThinkPad': 800,'Apple': 450} - - defShop (Money): +d1={} - forIinchD: + ifMoney>D[i]: Ad1[i]=D[i] at PrintD1 - Print "the items you can purchase are:" - forIinchD1: - Print " "*12, - Print "%-9s$%d"%(I,d1[i]) -K=raw_input ("Please enter the item you want to buy >>>",) inL=k.split (' ') - PrintL to forIinchL: + ifI not inchD: - Print "Input error!" theK=raw_input ("Please re-enter:",) *L=[] $L=k.split (' ')Panax Notoginseng Else: - ifmoney<D[i]: the Print "Insufficient balance! " + Break Amoney-=D[i] the Print "the items you purchased are:" + forIinchRange (len (l)): - Print "%20s"%(L[i]) $ $ Print "your balance still has%d, do you want to continue [y/n]? "% Money -k=raw_input () - ifk=="y" ork=="Y": the Shop (Money) - elifk=="N" ork=="N":Wuyi Print "Thank you for coming and wishing you a happy life! " the Exit - Else:Print "input error, enter Y or n, case insensitive! " WuShop (Money)
python-Shopping Cart