Python Little Exercise 008

Source: Internet
Author: User

The realization of the simple shopping procedure. (initial version)

1 #简易购物程序2 3Money =200004Goods_list = ['IPhone 8','Bicycle','Banana','Xiaomi Note','MacBook','Mineral Water']5Goods_price = [9000, -, -,3200,12000,5]6Print"Welcome to Smart Mall! You have a total of%d balances on your card. "%Money )7 print ()8Print'Product Information:')9Count =0Ten  whileCount <Len (goods_list): OnePrint'Item Number:%d'% count +"   "+ Goods_list[count] +'----'+ str (Goods_price[count]) +'Yuan', end="\ n") ACount + =1 - print () -Flag =True theBuy_lists = [] -Buy_price = [] -  whileflag: - print () +num =int(Input ("Please enter the number of items to be purchased:")) - print () +     ifNum <Len (goods_list): A         ifnum = =0and Money >=Goods_price[num]: atMoney-=int(Goods_price[num]) -Print"you have purchased%s"% Goods_list[num],'%d elements remaining'%Money ) - buy_lists.append (Goods_list[num]) - buy_price.append (Goods_price[num]) -elif num = =1and Money >=Goods_price[num]: -Money-=int(Goods_price[num]) inPrint"you have purchased%s"% Goods_list[num],'%d elements remaining'%Money ) - buy_lists.append (Goods_list[num]) to buy_price.append (Goods_price[num]) +elif num = =2and Money >=Goods_price[num]: -Money-=int(Goods_price[num]) thePrint"you have purchased%s"% Goods_list[num],'%d elements remaining'%Money ) * buy_lists.append (Goods_list[num]) $ buy_price.append (Goods_price[num])Panax Notoginsengelif num = =3and Money >=Goods_price[num]: -Money-=int(Goods_price[num]) thePrint"you have purchased%s"% Goods_list[num],'%d elements remaining'%Money ) + buy_lists.append (Goods_list[num]) A buy_price.append (Goods_price[num]) theelif num = =4and Money >=Goods_price[num]: +Money-=int(Goods_price[num]) -Print"you have purchased%s"% Goods_list[num],'%d elements remaining'%Money ) $ buy_lists.append (Goods_list[num]) $ buy_price.append (Goods_price[num]) -elif num = =5and Money >=Goods_price[num]: -Money-=int(Goods_price[num]) thePrint"you have purchased%s"% Goods_list[num],'%d elements remaining'%Money ) - buy_lists.append (Goods_list[num])Wuyi buy_price.append (Goods_price[num]) the         Else: -Print"Insufficient balance! ") WuFlag =False -     Else: AboutPrint"Please enter the correct product number! ") $ print () -  forMinchRange (len (buy_lists)): -BUY_LISTS[M] + ='--'+ str (buy_price[m]) +'Yuan' -Print"you have purchased%d items:%s"% (Len (buy_lists),' , '. Join (buy_lists)) +'\ n'+'%d dollars left on your card'% (Money) +'\ n'+'Welcome to the next visit! ')

Operation Result:

Python Little Exercise 008

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.