Python tuples, lists, dictionary exercises

Source: Internet
Author: User

#coding = Utf-8goods_data = (["Iphone7", 8000],["Mac Pro", 12000],["bike", +]) buyed_goods =[]def display_menu (): mes =    "' ****** shopping mall system ****** 1.%s%d 2.%s%d 3.%s%d 4. Exit System ************************    "% (Goods_data[0][0],goods_data[0][1],goods_data[1][0],goods_data[1][1],goods_data[2][0],goods_data[2][1])  Print (MES) def showbought (buyed_goods): length = Len (buyed_goods) mes = '---shopping list---' Print (MES) for I in (buyed_goods): Print (i) def toselect (): Display_menu () selected = Int (Input ("select:")) return Selectedyu e = Int (input ("Enter Amount:")) while True:se =toselect () if (SE = = 1 and yue >= goods_data[0][1]): Buyed_goods.ap Pend ([goods_data[0][0],goods_data[0][1]]) Yue-= goods_data[0][1] Print ("The purchase of the product%s was successful, cost%d RMB, the balance is:%d"% (Goods_ Data[0][0], Goods_data[0][1],yue)) Continue if (SE ==2 and Yue >= goods_data[1][1]): buyed_goods.append ([goods_data[1][0], goods_data[1][1]]) Yue-= goods_data[1][1] Print ("The purchase of the product%s was successful, cost%d RMB, the balance is:%d"% (Goods_data[1][0], goods_data[1][1], Yue)) Continue if (SE ==3 and Yue >= goods_data[2][1]): Buyed_goods.append ([goods_data[2][0], goods_data[2][        1]]) yue-= goods_data[2][1] Print ("The purchase of the product%s was successful, cost%d RMB, the balance is:%d"% (Goods_data[2][0], Goods_data[2][1],yue)) Continue Else:print ("Insufficient balance!!! ") Showbought (buyed_goods) break

  

Python tuples, lists, dictionary exercises

Related Article

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.