1. 程式人生 > >Python自動化開發-EX03(購物車實現)

Python自動化開發-EX03(購物車實現)

app num append 自動化 for pytho inpu python 輸出

#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Author:DaShuang.Gu
‘‘‘要求:
買家
1.商品信息存在文件裏
2.已購商品,余額記錄。第一次啟動程序時需要記錄工資,第二次啟動程序時顯示出上次余額
3.允許用戶根據商品編號購買商品
4.用戶選擇商品後,檢測是否夠,夠就直接扣款,不夠就提醒
5.可隨時退出,退出時,打印移購買商品和余額
商家入口:
可以添加商品,修改商品價格,運行程序輸出第一級菜單

 
‘‘‘
product_list = [
    (Iphone,5800),
    (Mac Pro,9800),
    (
Bike,800), (Watch,10600), (Coffee,31), (Alex Python,120), ] shopping_list = [] user_salary = input("請輸入你的薪水:") if user_salary.isdigit(): user_salary = int(user_salary) while True: #打印出商品信息 print(Product list.center(30, *)) for index,item in enumerate(product_list): print(index,item) #
break shopping_number = input("輸出你要買的商品編號:") if shopping_number.isdigit(): shopping_number = int(shopping_number) if shopping_number < len(product_list) and shopping_number >= 0: p_item = product_list[shopping_number] if user_salary >= p_item[1
]: shopping_list.append(p_item) user_salary -= p_item[1] print("商品%s加入到購物車,還有余額%s" % (p_item, user_salary)) else: print(余額不足%s % user_salary) else: print(輸入的產品編號不存在) elif shopping_number == q: print(shopping list.center(30,*)) for i in shopping_list: print(i) print("還乘余額%s"%user_salary) exit()

Python自動化開發-EX03(購物車實現)