-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwallet.py
35 lines (30 loc) · 940 Bytes
/
wallet.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
from student import *
class Wallet(object):
def __init__(self, person, rich):
self.person = person
self.rich = rich
if self.rich == True:
self.coins = 300
else:
self.coins = 100
def checkBalance(self):
return self.coins
def deposit(self, amount):
self.coins += amount
def purchase(self, amount):
if self.coins - amount >= 0:
self.coins -= amount
return True
return False
def donate(self, donator, receiver, amount):
if receiver == 'CMU':
if self.coins-amount >= 0:
donator.happiness += 10
self.coins -= amount
return True
elif receiver == 'charity':
if self.coins-amount >= 0:
donator.happiness += 25
self.coins -= amount
return True
return False