-
Notifications
You must be signed in to change notification settings - Fork 59
/
Copy pathatm_machine.py
123 lines (108 loc) · 3.12 KB
/
atm_machine.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
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
###########################################
# ATM Machines
# ------------
# Models an ATM machine in python. Contains the
# following functions:
#
# deposit: adds money to an account.
# withdrawal: withdraws money from an account.
# check_balance: check the current account balance.
# get_transactions: shows the date and amount of recent transaction.
# get_withdrawals: returns the cash.
# pin: get your pin number.
# get_name: get the customer's name.
#
# By Doug Purcell
# http://www.purcellconsult.com
#
#############################################
import datetime
class Atm:
"""
Models an ATM machine in python using
oop.
"""
def __init__(self, name, pin):
self.name = input("What's your name? ")
self.name = self.name.capitalize()
print('Welcome to Your Virtual ATM {} '.format(self.name))
self.amount = 0
self.transactions = dict()
self.withdrawals = dict()
self.pin = ''
if pin.isdigit() and len(pin) == 4:
self.pin = pin
else:
raise ValueError('Invalid Pin Number')
self.customer_account = dict()
self.customer_account.update(name=self.name)
self.customer_account.update(pin=self.pin)
def deposit(self, cash):
"""
Deposits money into an account as long
as the deposit is less than $1000 and greater
than $0.
"""
if cash > 0 < 1000:
self.amount += cash
date_stamp = str(datetime.datetime.now())
self.transactions.update(transaction=[date_stamp, cash])
else:
print('Transaction Declined.')
def withdraw(self, cash):
"""
withdraw money from the atm machine.
"""
if cash > 0 < 500:
if cash > self.amount:
print('Insufficient funds in account')
elif cash < 1:
print('Invalid amount. Enter at least $1')
else:
self.amount -= cash
date_stamp = str(datetime.datetime.now())
self.withdrawals.update(withdrawal=[date_stamp, -cash])
def check_balance(self):
"""
returns the current balance
of the account.
"""
return self.amount
def get_transactions(self):
"""
returns the account details.
"""
return self.transactions
def get_withdrawals(self):
"""
returns the recent withdrawal.
"""
return self.withdrawals
def get_pin(self):
"""
gets the pin
"""
return self.pin
def get_name(self):
"""
returns the name of the customer.
"""
return self.name
jack = Atm('Jack', '3282')
jack.deposit(100)
print(jack.get_transactions())
jack.deposit(200)
print(jack.get_transactions())
jack.withdraw(10)
print(jack.get_withdrawals())
jack.deposit(100)
print(jack.get_transactions())
jack.withdraw(100)
print(jack.get_withdrawals())
print(jack.get_pin())
print(jack.get_name())
jill = Atm('Jill', '29321')
henry = Atm('henry', '3821')
henry.deposit(1000)
print(henry.get_transactions())
henry.withdraw(2000)