Python path-Basic data type

Source: Internet
Author: User

#作业一: 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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.