-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathnewtype.py
65 lines (53 loc) · 2.08 KB
/
newtype.py
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
import time
class bank:
def __init__(self):
self.__cards = {"623887": ["111222", 100], "768875": ["167158", 200]}
self.__card = ""
self.__passwd = 0
self.__logfile = open("log.txt", "a", encoding="utf-8")
def __str__(self):
return "[Object bank]"
def __log(self, message: str):
self.__logfile.write("[%s]%s\n" % (time.asctime(time.localtime(time.time())), message))
self.__logfile.close()
self.__logfile = open("log.txt", "a", encoding="utf-8")
def login(self):
self.__card = str(input("卡号>"))
self.__passwd = input("密码>")
if self.__card in self.__cards:
if self.__passwd == self.__cards[self.__card][0]:
self.__log(self.__card + " successfully login")
return [True]
else:
self.__log(self.__card + " passwd not match")
return [False]
else:
self.__log("user not match")
return [False]
def purchase(self, money: float or int):
self.__cards[self.__card][1] += money
self.__log(self.__card + " purchase " + str(money))
return True
def getMoney(self):
self.__log(str(self.__card) + " successfully get money " + str(self.__cards[self.__card][1]))
return self.__cards[self.__card][1]
def takeMoney(self, amount: float or int):
if amount < self.getMoney():
self.__cards[self.__card][1] -= amount
self.__log(str(self.__card) + " successfully take money " + str(amount))
return True
else:
return False
main = bank()
if main.login()[0]:
while True:
a = int(input("请选择功能:\n1.查询余额\n2.存款\n3.取款\n>"))
if a == 1:
print(main.getMoney())
elif a == 2:
tmp = main.purchase(float(input("存额>")))
if tmp:
print("存款成功,当前余额" + str(main.getMoney()))
elif a == 3:
if main.takeMoney(float(input("取额"))):
print("取钱成功")