This repository was archived by the owner on Oct 27, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
146 lines (129 loc) · 5.08 KB
/
Copy pathmain.py
File metadata and controls
146 lines (129 loc) · 5.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
class bank:
def __init__(self):
self.accountDict = {}
def inputCheck(self, email, password):
if email not in self.accountDict:
return 'EmailNotFound'
if self.accountDict[email]['password'] != password:
return 'PasswrodError'
return None
def createAccount(self, email, password, name):
if email in self.accountDict:
return 'EmailUsed'
if not name:
return 'NameNull'
self.accountDict[email] = {'name': name, 'password': password, 'deposit': 0}
return 'CreateSuccessful'
def deleteAccount(self, email, password):
check = Bank.inputCheck(email, password)
if check:
return check
confirm = input(f'是否確定刪除{self.accountDict[email]["name"]}( True/False ): ')
if confirm == 'True':
del self.accountDict[email]
return 'ActionSuccessful'
if confirm == 'False':
return 'ActionCancel'
return 'UnknowAction'
def saveMoney(self, email, password, amount):
check = Bank.inputCheck(email, password)
if check:
return check
if amount.isdigit():
amount = int(amount)
self.accountDict[email]['deposit'] += amount
return 'SaveSuccessful'
return 'AmountEnterError'
def takeMoney(self, email, password, amount):
check = Bank.inputCheck(email, password)
if check:
return check
if amount.isdigit():
amount = int(amount)
if self.accountDict[email]['deposit'] < amount:
return 'DepositNotEnough'
self.accountDict[email]['deposit'] -= amount
return 'TakeSuccessful'
return 'AmountEnterError'
def showDeposit(self, email, password):
check = Bank.inputCheck(email, password)
if check:
return check
return self.accountDict[email]['deposit']
Bank = bank()
def output(string:str):
stringDict = {
# Null
'EmailNull': '[Error] 請輸入E-mail',
'PasswordNull': '[Error] 請輸入密碼',
'NameNull': '[Error] 請輸入帳戶名稱',
'AmountNull': '[Error] 請輸入金額',
# Account Error
'EmailNotFound': '[Error] 資料庫內無此E-mail',
'EmailUsed': '[Error] E-mail已使用',
'PasswrodError': '[Error] 密碼輸入錯誤',
# Action
'ActionSuccessful': '操作成功',
'ActionCancel': '[Error] 操作取消',
'UnknowAction': '[Error] 未知的操作',
'SaveSuccessful': '成功存入銀行帳戶',
'TakeSuccessful': '取款成功',
# Amount
'AmountEnterError': '[Error] 金額輸入錯誤',
# Deposit
'DepositNotEnough': '[Error] 存款不足',
# Account
'CreateSuccessful': '帳戶創建成功'
}
return stringDict[string]
def line(): print('='*100)
line()
print('本系統由芒果凍布丁製作', '有問題請至Discord找本作者: YT Mango#4092', 'Github: https://github.com/EvanHsieh0415', '本著作使用創用CC授權 CC BY-NC-ND 3.0 TW', sep='\n')
line()
print('歡迎來到芒果銀行!!!', '若您是新用戶,請先創建帳戶 輸入"create account")', '刪除帳戶 請輸入"delete account"', '存款 請輸入"save money"', '取款 請輸入"take money"', '離開此系統 請輸入"leave"', sep='\n')
line()
tragger = True
while tragger:
action = input('輸入您要進行的操作: ')
if not action:
print('[Error] 請輸入操作名稱')
line()
continue
if action not in ('create account', 'delete account', 'save money', 'take money', 'leave'):
print('[Error] 請輸入正確的操作')
line()
continue
if action == 'leave':
print('程式關閉')
tragger = False
if action in ('create account', 'delete account', 'save money', 'take money'):
email = input('請輸入E-mail: ')
if not email:
print(output('EmailNull'))
line()
continue
password = input('請輸入密碼: ')
if not password:
print(output('PasswordNull'))
line()
continue
if action in ('save money', 'take money'):
amount = input('請輸入金額: ')
if not amount:
print(output('AmountNull'))
line()
continue
if action == 'create account':
name = input('請輸入使用者名稱: ')
out = Bank.createAccount(email, password, name)
elif action == 'delete account':
out = Bank.deleteAccount(email, password)
elif action == 'save money':
out = Bank.saveMoney(email, password, amount)
elif action == 'take money':
out = Bank.takeMoney(email, password, amount)
print(output(out))
if out in ('SaveSuccessful', 'TakeSuccessful', 'DepositNotEnough'):
print(f'存款餘額: {Bank.showDeposit(email, password)}')
line()
input('Press any key to continue . . .')