#作业一: Jump out of the multilayer loop, three-layer loop, in the innermost, jump directly
Exit_flag = True#exit Flag bit forIinchRange (3): ifExit_flag = =True:Print('I---->', i) forJinchRange (3): ifExit_flag = =True:Print('J--->', J) forKinchRange (3): Print('k--->', K)ifK==1: Exit_flag=False Break Else: Break Else: BreakPrint('Last line!')View Code
# Job Two: Shopping cart program:
#你可以买下的东西: 1 iphone:5800 2 Coffee 3 Book 4 condom 90
#选择你要买的东西
#判断是否买的起
#放入购物车, deduct money, print balance
#还可以继续选择购买
money = Int (input ("Please enter how many dollars you have:")) Goods= ['iphone','Coffee',' Book','Shirt','Chocolate']#Product ListPrice = [5800,300,500,1000,50]#Commodity priceBuy_num = [0,0,0,0,0]#Add to cart the number of each itemTotal = 0#There are a few things to add to the shopping cart as a judgment of whether there is enough to buy the goodsExit_flag = True#exit Flag bitRemain_money = Money#the rest of the moneyPrint("Our store has the following products:") forIinchRange (goods.__len__()):#print a list of items Print(I,goods[i],price[i]) whileExit_flag = =True:number= Int (Input ("Please enter the product label you want to buy:")) ifNumber >= goods.__len__(): Choice= Input ("product does not exist, exit? (y,n)") ifChoice = ="y": Exit_flag=FalseElse: Count= Int (Input ("Please enter the few you would like to buy:")) Buy_num[number]+=count#The number of items purchased in the Buy_num to the corresponding locationRemain_money = Remain_money-price[number]*count#Deduct Money ifRemain_money >=0:Print("you still have", Remain_money,"Yuan") Choice= Input ("quit? (y,n)") ifChoice = ="y": Exit_flag=FalseElse: Print("the money is not enough!!! ") Remain_money= Remain_money + Price[number]*count#no purchase success, before the operation of the money and purchase quantityBuy_num[number]-=count#no purchase success, before the operation of the money and purchase quantity Print("you still have", Remain_money,"Yuan","the items you choose need to be spent", Price[number]*count,"Yuan") Choice= Input ("quit? (y,n)") ifChoice = ="y": Exit_flag=False forIinchRange (Buy_num.__len__()): Total+=Buy_num[i]ifTotal = =0:Print("you didn't buy any goods")Else: Print("------------------------------Shopping list---------------------------------") Print("you have purchased the following items:") forIinchRange (Buy_num.__len__()): ifBuy_num[i] >0:Print(Goods[i],'----', Buy_num[i],'a')Print('you still have', Remain_money,'Yuan')View Code
Python path-Basic data type