日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問(wèn) 生活随笔!

生活随笔

當(dāng)前位置: 首頁(yè) > 编程语言 > python >内容正文

python

Python学习day5作业

發(fā)布時(shí)間:2025/6/17 python 40 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Python学习day5作业 小編覺(jué)得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

目錄

  • Python學(xué)習(xí)day5作業(yè)
    • ATM和購(gòu)物商城
      • 1. 程序說(shuō)明
      • 2. 基本流程圖
      • 3. 程序測(cè)試帳號(hào)
      • 4. 程序結(jié)構(gòu):
      • 5. 程序測(cè)試

title: Python學(xué)習(xí)day5作業(yè)
tags: python
author: Chinge Yang
date: 2017-01-27
---

Python學(xué)習(xí)day5作業(yè)

@(學(xué)習(xí))[python]

ATM和購(gòu)物商城

作業(yè)需求

ATM:

  • 指定最大透支額度
  • 可取款
  • 定期還款(每月指定日期還款,如15號(hào))
  • 可存款
  • 定期出賬單
  • 支持多用戶登陸,用戶間轉(zhuǎn)帳
  • 支持多用戶
  • 管理員可添加賬戶、指定用戶額度、凍結(jié)用戶等
  • 購(gòu)物車(chē):

  • 商品信息- 數(shù)量、單價(jià)、名稱(chēng)
  • 用戶信息- 帳號(hào)、密碼、余額
  • 用戶可充值
  • 購(gòu)物歷史信息
  • 允許用戶多次購(gòu)買(mǎi),每次可購(gòu)買(mǎi)多件
  • 余額不足時(shí)進(jìn)行提醒
  • 用戶退出時(shí) ,輸出當(dāng)次購(gòu)物信息
  • 用戶下次登陸時(shí)可查看購(gòu)物歷史
  • 商品列表分級(jí)顯示
  • 1. 程序說(shuō)明

    購(gòu)物商城實(shí)現(xiàn)功能如下:

    • [x] 博客
    • [x] 多用戶登錄
    • [x] 商品按二級(jí)菜單顯示
    • [x] 充值功能
    • [x] 多次購(gòu)買(mǎi),每次購(gòu)買(mǎi)多件
    • [x] 余額不足提示充值
    • [x] 可查看購(gòu)物歷史

    ATM實(shí)現(xiàn)功能如下:

    • [x] 指定最大透支額度
    • [x] 可取款
    • [ ] 定期還款(每月指定日期還款,如15號(hào))
    • [x] 可存款
    • [x] 定期出賬單
    • [x] 支持多用戶登陸,用戶間轉(zhuǎn)帳
    • [x] 支持多用戶
    • [x] 管理員可添加賬戶、指定用戶額度、凍結(jié)用戶等

    ygqygq2的博客地址
    作業(yè)地址:https://git.oschina.net/ygqygq2/python_homework/tree/master/day5作業(yè)

    2. 基本流程圖

    3. 程序測(cè)試帳號(hào)

    用戶/密碼:
    ATM普通用戶:1000/abc、1001/1001
    ATM管理用戶:admin/abc
    購(gòu)物商城:test/test

    4. 程序結(jié)構(gòu):

    . ├── Atm # ATM主程目錄 │ ├── __init__.py │ ├── api # ATM程序API目錄 │ │ ├── __init__.py │ │ ├── __pycache__ │ │ │ ├── __init__.cpython-35.pyc │ │ │ └── pay1.cpython-35.pyc │ │ └── pay.py # ATM支付api │ ├── bin # ATM執(zhí)行文件目錄 │ │ ├── __init__.py │ │ ├── atm.py # ATM執(zhí)行程序,普通用戶登錄入口 │ │ └── manager.py # ATM管理員登錄入口 │ ├── conf # ATM配置目錄 │ │ ├── __init__.py │ │ ├── __pycache__ │ │ │ ├── __init__.cpython-35.pyc │ │ │ └── settings.cpython-35.pyc │ │ └── settings.py # ATM配置文件 │ ├── core # ATM主要邏輯程序目錄 │ │ ├── __init__.py │ │ ├── __pycache__ │ │ │ ├── __init__.cpython-35.pyc │ │ │ ├── accounts.cpython-35.pyc │ │ │ ├── auth.cpython-35.pyc │ │ │ ├── bill_date.cpython-35.pyc │ │ │ ├── db_handler.cpython-35.pyc │ │ │ ├── logger.cpython-35.pyc │ │ │ ├── main.cpython-35.pyc │ │ │ └── transaction.cpython-35.pyc │ │ ├── accounts.py # 用于從文件里加載和存儲(chǔ)賬戶數(shù)據(jù) │ │ ├── auth.py # 用于帳戶認(rèn)證和帳戶操作 │ │ ├── bill_date.py # 根據(jù)年-月,生成帳單起止時(shí)間模塊 │ │ ├── db_handler.py # 數(shù)據(jù)庫(kù)連接引擎 │ │ ├── logger.py # 日志記錄模塊 │ │ ├── main.py # 主邏輯程序 │ │ └── transaction.py # 記賬\還錢(qián)\取錢(qián)等所有的與賬戶金額相關(guān)的操作模塊 │ ├── db # 用戶數(shù)據(jù)存儲(chǔ)目錄 │ │ ├── __init__.py │ │ ├── account_sample.py # 生成一個(gè)初始的賬戶數(shù)據(jù) ,把這個(gè)數(shù)據(jù)存成一個(gè)以這個(gè)賬戶id為文件名的文件,放在accounts目錄就行了,程序自己去會(huì)這里找 │ │ └── accounts # 存各個(gè)用戶的賬戶數(shù)據(jù),一個(gè)用戶一個(gè)文件 │ │ ├── 1000.json # 一個(gè)普通用戶賬戶文件 │ │ └── admin.json # 一個(gè)管理員用戶示例文件 │ ├── docs # 程序說(shuō)明文檔目錄 │ │ └── __init__.py │ └── log # 日志根目錄 │ ├── __init__.py │ ├── access.log # 用戶訪問(wèn)和操作的相關(guān)日志 │ ├── accounts # 存各個(gè)用戶的帳單數(shù)據(jù),一個(gè)用戶一個(gè)文件 │ │ └── 1000.bills # 一個(gè)普通用戶的帳單文件 │ └── transactions.log # 所有的交易還款等日志 ├── README.md # readme文件 └── Shopping_mall # 購(gòu)物商城程序目錄├── bin # 購(gòu)物商城執(zhí)行文件目錄│ ├── __init__.py│ └── shopping_mall.py # 購(gòu)物商城入口程序├── conf # 購(gòu)物商城配置目錄│ ├── __init__.py│ ├── __pycache__│ │ ├── __init__.cpython-35.pyc│ │ ├── goods.cpython-35.pyc│ │ └── settings.cpython-35.pyc│ ├── goods.py # 購(gòu)物商城商品價(jià)格列表│ └── settings.py # 購(gòu)物商城配置文件├── core # 購(gòu)物商城主要邏輯程序目錄│ ├── __init__.py│ ├── __pycache__│ │ ├── __init__.cpython-35.pyc│ │ ├── accounts.cpython-35.pyc│ │ ├── auth.cpython-35.pyc│ │ ├── db_handler.cpython-35.pyc│ │ ├── logger.cpython-35.pyc│ │ ├── main.cpython-35.pyc│ │ └── shopping.cpython-35.pyc│ ├── accounts.py # 用于從文件里加載和存儲(chǔ)賬戶數(shù)據(jù)│ ├── auth.py # 用于帳戶認(rèn)證和帳戶操作│ ├── db_handler.py # 數(shù)據(jù)庫(kù)連接引擎│ ├── logger.py # 日志記錄模塊│ └── main.py # 主邏輯程序├── db # 用戶數(shù)據(jù)存儲(chǔ)目錄│ └── accounts # 存各個(gè)用戶的賬戶數(shù)據(jù),一個(gè)用戶一個(gè)文件│ ├── __init__.py│ └── test.json # 一個(gè)普通用戶賬戶文件└── log├── access.log # 用戶訪問(wèn)和操作的相關(guān)日志└── test_shopping.log # 用戶購(gòu)物歷史日志

    5. 程序測(cè)試

  • 管理員登錄失敗
    python Atm/bin/manager.py
  • ################ATM admin manager################# account:a password:a Account [a] does not exist! account:a password:a Account [a] does not exist! account:a password:a Account [a] does not exist! 2017-01-27 01:47:07,377 - access - ERROR - account [a] too many login attemptsProcess finished with exit code 0
  • 管理員登錄(不允許普通用戶登錄)
    python Atm/bin/manager.py
  • ################ATM admin manager################# account:1000 password:abc Permission deniedProcess finished with exit code 0 ################ATM admin manager################# account:admin password:abc------- Admin erea ---------1. 添加賬戶2. 查詢用戶信息3. 用戶信息修改(凍結(jié)帳戶、用戶信用卡額度等)4. 生成全部用戶帳單5. 退出>>:1001 Option does not exist!------- Admin erea ---------1. 添加賬戶2. 查詢用戶信息3. 用戶信息修改(凍結(jié)帳戶、用戶信用卡額度等)4. 生成全部用戶帳單5. 退出>>:1 account id:1001 password:1001 Account [1001] is exist,try another account. account id:1002 password:1002 account [1002] added sucessed------- Admin erea ---------1. 添加賬戶2. 查詢用戶信息3. 用戶信息修改(凍結(jié)帳戶、用戶信用卡額度等)4. 生成全部用戶帳單5. 退出>>:2 Please input your query account id:1002 pay_day :22 credit :15000 status :0 balance :15000 id :1002 enroll_date :2017-01-27 expire_date :2022-01-26 ------- Admin erea ---------1. 添加賬戶2. 查詢用戶信息3. 用戶信息修改(凍結(jié)帳戶、用戶信用卡額度等)4. 生成全部用戶帳單5. 退出>>:2 Please input your query account id:1001 pay_day :22 credit :15000 status :0 id :1001 balance :15000 enroll_date :2017-01-27 expire_date :2022-01-26 ------- Admin erea ---------1. 添加賬戶2. 查詢用戶信息3. 用戶信息修改(凍結(jié)帳戶、用戶信用卡額度等)4. 生成全部用戶帳單5. 退出>>:>>:3 account id:1001 You can choose the items like this: {"password": "abc","credit": 15000,"status": 0,"expire_date": "2021-01-01","pay_day": 22 } Input modify items(json):{"credit":20000,"pay_day": 23} Account infomation updated!------- Admin erea ---------1. 添加賬戶2. 查詢用戶信息3. 用戶信息修改(凍結(jié)帳戶、用戶信用卡額度等)4. 生成全部用戶帳單5. 退出>>:2 Please input your query account id:1001 pay_day :23 credit :20000 status :0 balance :15000 id :1001 enroll_date :2017-01-27 expire_date :2022-01-26 ------- Admin erea ---------1. 添加賬戶2. 查詢用戶信息3. 用戶信息修改(凍結(jié)帳戶、用戶信用卡額度等)4. 生成全部用戶帳單5. 退出>>:>>:2 Please input your query account id:0 Get account [0] info pemission denied!------- Admin erea ---------1. 添加賬戶2. 查詢用戶信息3. 用戶信息修改(凍結(jié)帳戶、用戶信用卡額度等)4. 生成全部用戶帳單5. 退出>>>>:2 Please input your query account id:0 Get account [0] info pemission denied!------- Admin erea ---------1. 添加賬戶2. 查詢用戶信息3. 用戶信息修改(凍結(jié)帳戶、用戶信用卡額度等)4. 生成全部用戶帳單5. 退出>>>>:2 Please input your query account id:0 Get account [0] info pemission denied!------- Admin erea ---------1. 添加賬戶2. 查詢用戶信息3. 用戶信息修改(凍結(jié)帳戶、用戶信用卡額度等)4. 生成全部用戶帳單5. 退出>>:4 ------------------Account bill:------------------- -----------------------End------------------------ ------------------Account bill:------------------- expire_date :2021-01-01 credit :15000 enroll_date :2016-01-02 status :0 balance :4265.0 pay_day :22 id :1000 Today is not the bill generation day! Account [1000] need to repay [10735.0] -----------------------End------------------------ ------------------Account bill:------------------- expire_date :2022-01-26 id :1001 pay_day :23 status :0 balance :15000 enroll_date :2017-01-27 credit :20000 Today is not the bill generation day! Account [1001] need to repay [5000] -----------------------End------------------------ ------------------Account bill:------------------- expire_date :2022-01-26 credit :15000 pay_day :22 status :0 balance :15000 enroll_date :2017-01-27 id :1002 Today is not the bill generation day! Account [1002] needn't to repay. -----------------------End------------------------ ------------------Account bill:------------------- -----------------------End------------------------------- Admin erea ---------1. 添加賬戶2. 查詢用戶信息3. 用戶信息修改(凍結(jié)帳戶、用戶信用卡額度等)4. 生成全部用戶帳單5. 退出>>:5 ###################Bye,thanks!####################
  • 普通用戶登錄(不允許管理員登錄)
    python Atm/bin/atm.py
  • ##################Welcome to ATM################## account:1000 password:abc------- Oldboy Bank ---------1. 賬戶信息2. 還款(示例)3. 取款(示例)4. 轉(zhuǎn)賬5. 存款6. 賬單7. 退出>>:1 status :0 pay_day :22 enroll_date :2016-01-02 balance :4265.0 expire_date :2021-01-01 credit :15000 id :1000 ------- Oldboy Bank ---------1. 賬戶信息2. 還款(示例)3. 取款(示例)4. 轉(zhuǎn)賬5. 存款6. 賬單7. 退出>>:2--------- BALANCE INFO --------Credit : 15000Balance: 4265.0 Tip: [b] to back Input repay amount:200 2017-01-28 09:49:30,934 - transaction - INFO - account:1000 action:repay amount:200.0 interest:0.0 New Balance:4465.0 Tip: [b] to back Input repay amount:b------- Oldboy Bank ---------1. 賬戶信息2. 還款(示例)3. 取款(示例)4. 轉(zhuǎn)賬5. 存款6. 賬單7. 退出>>:3--------- BALANCE INFO --------Credit : 15000Balance: 4465.0 Tip: [b] to back Input withdraw amount:200 2017-01-28 09:49:44,162 - transaction - INFO - account:1000 action:withdraw amount:200.0 interest:10.0 New Balance:4255.0 Tip: [b] to back Input withdraw amount:b------- Oldboy Bank ---------1. 賬戶信息2. 還款(示例)3. 取款(示例)4. 轉(zhuǎn)賬5. 存款6. 賬單7. 退出>>:4--------- BALANCE INFO --------Credit : 15000Balance: 4255.0(Tip: input [b] to back) Input receiver:1001 Input transfer amount:200 2017-01-28 09:50:06,723 - transaction - INFO - account:1000 action:transfer amount:200.0 interest:10.0 New Balance:4045.02017-01-28 09:50:06,723 - transaction - INFO - account:1001 action:receive amount:200.0 interest:0.0Input receiver:b------- Oldboy Bank ---------1. 賬戶信息2. 還款(示例)3. 取款(示例)4. 轉(zhuǎn)賬5. 存款6. 賬單7. 退出>>:5--------- BALANCE INFO --------Credit : 15000Balance: 4045.0(Tip: input [b] to back) Input your save amount:400 2017-01-28 09:53:45,354 - transaction - INFO - account:1000 action:save amount:400.0 interest:0.0 New Balance:4445.0------- Oldboy Bank ---------1. 賬戶信息2. 還款(示例)3. 取款(示例)4. 轉(zhuǎn)賬5. 存款6. 賬單7. 退出>>:6 Please input the date you will query like [2016-12]>>>2016-12 Account [1000] bills: -------------------------------------------------- bill_date: 2017-1 account_id: 1000 need_repay: 10555bill_date: 2017-1 account_id: 1000 need_repay: 10555Account [1000] history log: -------------------------------------------------- --------------------------------------------------------- Oldboy Bank ---------1. 賬戶信息2. 還款(示例)3. 取款(示例)4. 轉(zhuǎn)賬5. 存款6. 賬單7. 退出>>:6 Please input the date you will query like [2016-12]>>>2017-01 Account [1000] bills: -------------------------------------------------- bill_date: 2017-1 account_id: 1000 need_repay: 10555bill_date: 2017-1 account_id: 1000 need_repay: 10555Account [1000] history log: -------------------------------------------------- 2017-01-25 21:33:43,281 - transaction - INFO - account:1000 action:pay amount:10000.0 interest:0.0 2017-01-25 22:16:26,609 - transaction - INFO - account:1000 action:pay amount:100.0 interest:0.0 2017-01-25 22:16:52,347 - transaction - INFO - account:1000 action:pay amount:100.0 interest:0.0 2017-01-26 21:47:42,372 - transaction - INFO - account:1000 action:repay amount:100.0 interest:0.0 2017-01-26 21:51:13,819 - transaction - INFO - account:1000 action:repay amount:100.0 interest:0.0 2017-01-26 21:51:24,608 - transaction - INFO - account:1000 action:withdraw amount:500.0 interest:25.0 2017-01-26 21:53:16,352 - transaction - INFO - account:1000 action:withdraw amount:200.0 interest:10.0 2017-01-28 09:49:30,934 - transaction - INFO - account:1000 action:repay amount:200.0 interest:0.0 2017-01-28 09:49:44,162 - transaction - INFO - account:1000 action:withdraw amount:200.0 interest:10.0 2017-01-28 09:50:06,723 - transaction - INFO - account:1000 action:transfer amount:200.0 interest:10.0 2017-01-28 09:53:45,354 - transaction - INFO - account:1000 action:save amount:400.0 interest:0.0 --------------------------------------------------------- Oldboy Bank ---------1. 賬戶信息2. 還款(示例)3. 取款(示例)4. 轉(zhuǎn)賬5. 存款6. 賬單7. 退出>>:7 ###################Bye,thanks!####################Process finished with exit code 1
  • 購(gòu)物商城已注冊(cè)用戶登錄
    python Shopping_mall/bin/shopping_mall.py
  • ------------Welcome to shopping mall!---------------------------------------------------------------1. Login2. Sign up3. Logout -------------------------------------------------->>:1 Please input your user name and password! user:test password:test Input [y|yes] to view your purchase history,[others] means not. Please input:y User test shopping history: -------------------------------------------------- 2017-01-17 17:15:39,199 - shopping - INFO - account:test action:shopping product_number:2 goods:Tea cost:29378 2017-01-17 17:22:13,163 - shopping - INFO - account:test action:shopping product_number:1 goods:Coffee cost:29348 2017-01-24 21:55:50,796 - shopping - INFO - account:test action:shopping product_number:2 goods:Milk cost:29230 2017-01-25 00:05:46,534 - shopping - INFO - account:test action:shopping product_number:1 goods:Coffee cost:29200 2017-01-25 00:06:07,089 - shopping - INFO - account:test action:shopping product_number:1 goods:Coffee cost:29170 2017-01-25 00:36:53,038 - shopping - INFO - account:test action:shopping product_number:1 goods:Coffee cost:29140 2017-01-25 21:33:07,174 - shopping - INFO - account:test action:shopping product_number:1 goods:Coffee cost:30110 -------------------Species list------------------- 0 --> Mobile phone 1 --> Car 2 --> Drink -----------------------End------------------------ [q|b] to quit;[c] to check;[t] to top up Input your choice:t Do you want to charge more money?[y|n|b]y Please use your ATM account to pay. Please input your top-up amount:1000 account:abc password:a Account [abc] does not exist! account:1000 password:abc 2017-01-28 10:31:52,106 - transaction - INFO - account:1000 action:pay amount:1000.0 interest:0.0 Pay successed Your balance is [41310] -------------------Species list------------------- 0 --> Mobile phone 1 --> Car 2 --> Drink -----------------------End------------------------ [q|b] to quit;[c] to check;[t] to top up Input your choice:2 ---->Enter Drink -------------------Product list------------------- 0.Milk 59 1.Coffee 30 2.Tea 311 -----------------------End------------------------ [q|quit] to quit;[b|back] to back;[c|check] to check Please choice the product:1 Please input the number of product:2 Added [2] [Coffee] into shopping cart,your balance is [40250] 2017-01-28 10:32:07,465 - shopping - INFO - account:test action:shopping product_number:2 goods:Coffee cost:40250 -------------------Product list------------------- 0.Milk 59 1.Coffee 30 2.Tea 311 -----------------------End------------------------ [q|quit] to quit;[b|back] to back;[c|check] to check Please choice the product:b -------------------Species list------------------- 0 --> Mobile phone 1 --> Car 2 --> Drink -----------------------End------------------------ [q|b] to quit;[c] to check;[t] to top up Input your choice:0 ---->Enter Mobile phone -------------------Product list------------------- 0.Iphone7 6188 1.Iphone7 plus 7888 2.Xiaomi5 2888 -----------------------End------------------------ [q|quit] to quit;[b|back] to back;[c|check] to check Please choice the product:0 Please input the number of product:1 2017-01-28 10:32:20,656 - shopping - INFO - account:test action:shopping product_number:1 goods:Iphone7 cost:34062 Added [1] [Iphone7] into shopping cart,your balance is [34062] -------------------Product list------------------- 0.Iphone7 6188 1.Iphone7 plus 7888 2.Xiaomi5 2888 -----------------------End------------------------ [q|quit] to quit;[b|back] to back;[c|check] to check Please choice the product:c *********You purchased products as below********** Goods Price Number Cost Iphone7 6188 1 6188 Coffee 30 2 60 ***********************End************************ You total cost: 6248 Your balance is [34062] -------------------Product list------------------- 0.Iphone7 6188 1.Iphone7 plus 7888 2.Xiaomi5 2888 -----------------------End------------------------ [q|quit] to quit;[b|back] to back;[c|check] to check Please choice the product:b -------------------Species list------------------- 0 --> Mobile phone 1 --> Car 2 --> Drink -----------------------End------------------------ [q|b] to quit;[c] to check;[t] to top up Input your choice:q *********You purchased products as below********** Goods Price Number Cost Iphone7 6188 1 6188 Coffee 30 2 60 ***********************End************************ You total cost: 6248 Your balance is [34062] ###################Bye,thanks!####################Process finished with exit code 1
  • 購(gòu)物商城新注冊(cè)用戶
    python Shopping_mall/bin/shopping_mall.py
  • ------------Welcome to shopping mall!---------------------------------------------------------------1. Login2. Sign up3. Logout -------------------------------------------------->>:2 user:test01 password:test01 -------------------Species list------------------- 0 --> Drink 1 --> Mobile phone 2 --> Car -----------------------End------------------------ [q|b] to quit;[c] to check;[t] to top up Input your choice:c *********You purchased products as below********** Goods Price Number Cost ***********************End************************ You total cost: 0 Your balance is [0] -------------------Species list------------------- 0 --> Drink 1 --> Mobile phone 2 --> Car -----------------------End------------------------ [q|b] to quit;[c] to check;[t] to top up Input your choice:q *********You purchased products as below********** Goods Price Number Cost ***********************End************************ You total cost: 0 Your balance is [0] ###################Bye,thanks!####################Process finished with exit code 1

    轉(zhuǎn)載于:https://www.cnblogs.com/ygqygq2/p/6354267.html

    總結(jié)

    以上是生活随笔為你收集整理的Python学习day5作业的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。

    如果覺(jué)得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。