-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathc1s.py
More file actions
42 lines (32 loc) · 713 Bytes
/
c1s.py
File metadata and controls
42 lines (32 loc) · 713 Bytes
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
# BANK ACCOUNT MODEL
# one Solution
balance = 0
# to deposit money
def deposit(amount):
global balance
balance += amount
return balance
# to withdraw money
def withdraw(amount):
global balance
balance -= amount
return balance
print(balance)
deposit(100)
print(balance)
withdraw(50)
print(balance)
# Another way to solve it
# using the dictionary local variable
def makeAccount():
return { 'balance': 0 }
def deposit(account, amount):
account['balance'] += amount
return account['balance']
def withdraw(account, amount):
account['balance'] -= amount
return account['balance']
a = makeAccount()
b = makeAccount()
print(deposit(a,500))
print(deposit(b,300))