Python Basics-Small program exercises

Source: Internet
Author: User

First, from the 3rd layer loop directly out of all loops

Break_flag =Falsecount=0 whileBreak_flag = =False:Print("-First Floor")     whileBreak_flag = =False:Print("Second Floor")         whileBreak_flag = =False:count+ = 1ifCount > 10: Break_flag=TruePrint("Third Floor")Print("Keep going ...")
With Break_flag

#Break_flag = FalseCount =0 whileCount < 3:    Print("-First Floor")     whileCount < 3:        Print("Second Floor")         whileCount <= 10: Count+ = 1#if Count >:            #Break_flag = True            Print("Third Floor")Print("Keep going ...")
without Break_flag

Second, the shopping cart procedure

Goods_list = [['Iphone7', 5800],['Coffee', 30],[' Book', 99],['Bike', 199],['Vivi X9', 2499]]#Product ListShopping_cart = []#User Shopping Cart listsalary = Int (input ('Input your Salary:'))#User Salarym =Salaryk=0 whileTrue:index=0 forGoodsinchGoods_list:#print a list of items        Print(index,goods) Index+ = 1Choice= Input ('>>>:'). Strip ()ifchoice.isdigit (): Choice=int (choice)ifChoice >= 0 andChoice <Len (goods_list): Goods=Goods_list[choice]ifGoods[1] <= Salary:#determine if the user has enough money to pay for the selected itemshopping_cart.append (goods) salary-= Goods[1]                Print('ADD Goods'+str (Goods[0]) +'into shopping cart! Your Current Balance:'+Str (salary))Else:                Print('No enough money! The price is:'+str (Goods[1]) +'! Need more:'+str (goods[1]-salary)) Else:            Print('Has no this goods!')    elifChoice = ='Q':        Print('----------Your Shopping Cart----------')        Print('ID Goods Quantity price total')         forIinchRange (len (goods_list)): J=Shopping_cart.count (Goods_list[i])ifJ >0:k+ = 1PrintK'\ t', Goods_list[i][0],'\ t'J'\t\t', Goods_list[i][1],'\ t', J * Goods_list[i][1])        Print('Total Price is:', M-salary) Break    Else:        Print('Has no this goods')
Shopping Cart Procedure

Python Basics-Small program exercises

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.