Python學醫第二天——購物車程式

來源:互聯網
上載者:User

標籤:tool   else   tin   phone   charm   class   pycharm   餘額   one   

程式:購物車程式

需求:

  1. 啟動程式後,讓使用者輸入工資,然後列印商品列表
  2. 允許使用者根據商品編號購買商品
  3. 使用者選擇商品後,檢測餘額是否夠,夠就直接扣款,不夠就提醒 
  4. 可隨時退出,退出時,列印已購買商品和餘額

 

#coding=utf-8#Version:python 3.6.0#Tools:Pycharm 2017.3.2_date_ = ‘2018/4/16/016 14:50‘_author_ = ‘Hongyong‘salary = int(input("Please input your salary: "))shoppingmart = []items = (["1. ","Huawei","¥",2800],         ["2. ","Earphone","¥",300],         ["3. ","Book","¥",80])print(items)while True:    shopindex = int(input("Please choose goods: "))    if salary > items[shopindex-1][3]:        shoppingmart.append(items[shopindex-1])        salary -= int(items[shopindex-1][3])        print("You have bought {name} !".format(name = items[shopindex-1][1]))        print("Your balance is: ¥",salary)        decision = input("Do you want to quit now?")        if decision == "q":            break        else:            continue    else:        print("Your balance is not enough! Please try sth else.")print("You have bought ",shoppingmart)

  

  

Python學醫第二天——購物車程式

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

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.