Python list Exercises

Source: Internet
Author: User

Python in Shopping cart practice

Requirements: You can enter a salary, select a commodity, and as long as the user has enough money to buy the goods, until the balance is insufficient, after the purchase is completed format the printing user's balance and merchandise.

#_ *_ coding:utf-8 _*_import sysshopping_car = []product_list_title =  ' Product list ' welcome =  ' welcome to the shopping ' product_list = [      (' iphone ', 3888),     (' ThinkPad ', 4888),     (' Coffee ', ,     (' Mac ', 6888)]print welcomesalary = input (' please input  Your salary: ') while true:    print product_list_title     for item in product_list:        print  Product_list.index (item) +1,item    choice = input (' Please input the  name of goods: ')     if choice > 4 or choice  < 0:        print  ' No such goods,please  reselect '         continue    elif choice <= 4 and  Choice >= 1:        if salary < product _list[choice-1][1]:            print  ' Account  balance is insufficient, please buy other products or quit '             continue         else:            shopping_ Car.append (product_list[choice-1]) #将商品添加到购物车              print  ' The goods you had buy '              for goods in shopping_car:                 print goods[0],goods[1]             salary = salary - product_list[choice-1][1]             print  ' your account balance is %s '  %salary    elif choice == 0:         print  ' your goods is  '         for  goods in shopping_car:             print goods[0], goods[1]        print  ' Your  Balance is ', salary        sys.exit (' Program exit!!! ')


Python list 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.