Skip to content

Commit 18bdd25

Browse files
committed
class code
1 parent 93d82f9 commit 18bdd25

File tree

2 files changed

+39
-0
lines changed

2 files changed

+39
-0
lines changed

snippets/classes.md

Whitespace-only changes.

snippets/classes.py

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
from __future__ import print_function
2+
import numpy as np
3+
4+
5+
class Account:
6+
7+
def __init__(self):
8+
self.amount = 0
9+
10+
def putMoney(self, deposit):
11+
print("my amount is", self.amount)
12+
self.amount += deposit
13+
print("my amount is", self.amount)
14+
15+
def takeMoney(self, withdrawal):
16+
self.amount -= withdrawal
17+
18+
def printAmount(self):
19+
print("my amount is", self.amount)
20+
print(self.amount)
21+
22+
23+
class BankAccount:
24+
25+
def __init__(self):
26+
self.accounts = [Account() for i in np.arange(1000)]
27+
28+
def putMoney(self, account, deposit):
29+
self.accounts[account].putMoney(deposit)
30+
31+
def takeMoney(self, account, withdrawal):
32+
self.accounts[account].takeMoney(withdrawal)
33+
34+
def printAmount(self, account):
35+
self.accounts[account].printAmount()
36+
37+
a = BankAccount()
38+
a.putMoney(5, 100)
39+
a.printAmount(5)

0 commit comments

Comments
 (0)