程序師世界是廣大編程愛好者互助、分享、學習的平台,程序師世界有你更精彩!
首頁
編程語言
C語言|JAVA編程
Python編程
網頁編程
ASP編程|PHP編程
JSP編程
數據庫知識
MYSQL數據庫|SqlServer數據庫
Oracle數據庫|DB2數據庫
您现在的位置: 程式師世界 >> 編程語言 >  >> 更多編程語言 >> Python

【Simulation Simple Banking System~python】

編輯:Python

目錄~python

  • Object-Oriented Programming for Simulating Banking System
    • 相關程序代碼如下:
      • 運行效果如下:
  • pandas 每日一練:
      • 運行結果為:
    • 66、繪制sku_cost_prc的密度曲線
      • 運行效果為:
    • 67、Calculate the next day and the previous daysku_cost_prc的差值
      • 運行結果為:
    • 68、Calculate the next day and the previous daysku_cost_prc變化率
      • 運行結果為:
    • 69、設置日期為索引
      • 運行結果為:
    • 70、以9個數據作為一個數據滑動窗口,在這5個數據上取均值(`sku_cost_prc`)
      • 運行結果為:
    • 每日一言:
      • 持續更新中...


個人昵稱:lxw-pro
個人主頁:歡迎關注 我的主頁
個人感悟: “失敗乃成功之母”,這是不變的道理,在失敗中總結,在失敗中成長,才能成為IT界的一代宗師.

Object-Oriented Programming for Simulating Banking System

現在呀,Although WeChat payment has been widely used、支付寶支付等,Think about WeChat、Alipay, etc. leave a balance,Still inseparable from our deposits,If you have a deposit, you must have cash,當然,ATMs are still as convenient ,“自己動手,豐衣足食”,那麼,How does our ATM know you've got so much?,How do you know your balance clearly?,Let's take a look at Kangkang's so-called simple analog system.!

相關程序代碼如下:

import datetime
class Bank(object):
account_log = []
def __init__(self, name):
self.name = name
def deposit(self, amount): # 存錢
user.balance += amount
self.write_log('存錢', amount)
def withdrawal(self, amount): # 取錢
if amount > user.balance:
print("余額不足")
else:
user.balance -= amount
self.write_log('取錢', amount)
def write_log(self, type, amount): # 寫日志
now = datetime.datetime.now()
ct = now.strftime("%Y-%m-%d %H:%M:%S")
data = [self.name, user.name, ct, type, amount, f"{user.balance:.2f}"]
Bank.account_log.append(data)
class User(object):
def __init__(self, name, balance):
self.name = name
self.balance = balance
def print_log(self):
for item in Bank.account_log:
print(item)
def show_menu():
menu = '''
0: 退出
1: 存款
2: 取款
3: 打印交易信息
'''
print(menu)
bank = Bank("貴陽銀行")
user = User('lxw-pro', 520)
while True:
show_menu()
num = int(input("請輸入菜單編號:"))
if num == 0:
print("退出系統")
break
elif num == 1:
print("存款")
amount = float(input("請輸入存款金額:"))
bank.deposit(amount)
print(f"The current amount is{user.balance:.2f}")
elif num == 2:
print("取款")
amount = float(input("請輸入取款金額:"))
bank.withdrawal(amount)
print(f"The current amount is{user.balance:.2f}")
elif num == 3:
print("查看記錄")
user.print_log()
else:
print("輸入有誤!")

運行效果如下:

看效果,有點長,So cut into two pictures

————————————————————————————————————————————

pandas 每日一練:

# -*- coding = utf-8 -*-
# @Time : 2022/7/29 15:15
# @Author : lxw_pro
# @File : pandas-11 練習.py
# @Software : PyCharm
import pandas as pd
import matplotlib.pyplot as plt
lxw = pd.read_excel("site.xlsx")
print(lxw)

運行結果為:

 Unnamed: 0 Unnamed: 0.1 create_dt ... yye sku_cost_prc lrl
0 0 1 2016-11-30 ... 8.8 6.77 30.00%
1 1 2 2016-11-30 ... 7.5 5.77 30.00%
2 2 3 2016-11-30 ... 5.0 3.85 30.00%
3 3 4 2016-11-30 ... 19.6 7.54 30.00%
4 4 5 2016-12-02 ... 13.5 10.38 30.00%
.. ... ... ... ... ... ... ...
751 751 752 2016-12-31 ... 1.0 0.77 30.00%
752 752 753 2016-12-31 ... 2.0 1.54 30.00%
753 753 754 2016-12-31 ... 1.0 0.77 30.00%
754 754 755 2016-12-31 ... 7.6 2.92 30.00%
755 755 756 2016-12-31 ... 3.3 2.54 30.00%
[756 rows x 8 columns]

66、繪制sku_cost_prc的密度曲線

lxw['sku_cost_prc'].plot(kind='kde')
plt.show()

運行效果為:


67、Calculate the next day and the previous daysku_cost_prc的差值

print(-lxw['sku_cost_prc'].diff())

運行結果為:

0 NaN
1 1.00
2 1.92
3 -3.69
4 -2.84
...
751 3.13
752 -0.77
753 0.77
754 -2.15
755 0.38
Name: sku_cost_prc, Length: 756, dtype: float64

68、Calculate the next day and the previous daysku_cost_prc變化率

print(-lxw['sku_cost_prc'].pct_change())

運行結果為:

0 NaN
1 0.147710
2 0.332756
3 -0.958442
4 -0.376658
...
751 0.802564
752 -1.000000
753 0.500000
754 -2.792208
755 0.130137
Name: sku_cost_prc, Length: 756, dtype: float64

69、設置日期為索引

data = lxw.set_index('create_dt')
print(data)

運行結果為:

 Unnamed: 0 Unnamed: 0.1 sku_cnt ... yye sku_cost_prc lrl
create_dt ...
2016-11-30 0 1 1.0 ... 8.8 6.77 30.00%
2016-11-30 1 2 1.0 ... 7.5 5.77 30.00%
2016-11-30 2 3 1.0 ... 5.0 3.85 30.00%
2016-11-30 3 4 2.0 ... 19.6 7.54 30.00%
2016-12-02 4 5 1.0 ... 13.5 10.38 30.00%
... ... ... ... ... ... ...
2016-12-31 751 752 1.0 ... 1.0 0.77 30.00%
2016-12-31 752 753 1.0 ... 2.0 1.54 30.00%
2016-12-31 753 754 1.0 ... 1.0 0.77 30.00%
2016-12-31 754 755 2.0 ... 7.6 2.92 30.00%
2016-12-31 755 756 1.0 ... 3.3 2.54 30.00%
[756 rows x 7 columns]

70、以9個數據作為一個數據滑動窗口,在這5個數據上取均值(sku_cost_prc

jz = data['sku_cost_prc'].rolling(10).mean()
print(jz)

運行結果為:

create_dt
2016-11-30 NaN
2016-11-30 NaN
2016-11-30 NaN
2016-11-30 NaN
2016-12-02 NaN
...
2016-12-31 5.016
2016-12-31 4.185
2016-12-31 3.500
2016-12-31 2.802
2016-12-31 2.066
Name: sku_cost_prc, Length: 756, dtype: float64

每日一言:

The top of self-discipline is to enjoy solitude!這一年裡,失去,釋懷,成長,Over half!!


持續更新中…

點贊,你的認可是我創作的動力
收藏,你的青睐是我努力的方向
評論,你的意見是我進步的財富
關注,你的喜歡是我長久的堅持

歡迎關注微信公眾號【程序人生6】,一起探討學習哦!!!


  1. 上一篇文章:
  2. 下一篇文章:
Copyright © 程式師世界 All Rights Reserved