標籤:tool else tin phone charm class pycharm 餘額 one
程式:購物車程式
需求:
- 啟動程式後,讓使用者輸入工資,然後列印商品列表
- 允許使用者根據商品編號購買商品
- 使用者選擇商品後,檢測餘額是否夠,夠就直接扣款,不夠就提醒
- 可隨時退出,退出時,列印已購買商品和餘額
#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學醫第二天——購物車程式