-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCreditCard.py
More file actions
59 lines (46 loc) · 1.67 KB
/
CreditCard.py
File metadata and controls
59 lines (46 loc) · 1.67 KB
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
class CreditCard:
""" Implementation of a credit card class. """
def __init__(self, customer, bank, account, limit):
""" create a new credit card instance. the initial balance is zero.
"""
self._customer = customer
self._bank = bank
self._account = account
self._limit = limit
self._balance = 0
def get_customer(self):
""" Return the name of the customer. """
return self._customer
def get_bank(self):
""" Return bank's name """
return self._bank
def get_account(self):
""" Return the card ID number"""
return self._account
def get_limit(self):
""" Return current credit limit. """
return self._limit
def get_balance(self):
""" Return current balance. """
return self._balance
def charge(self, price):
"""Charge given price to the card, assuming sufficient credit limit.
Return True if charge was processed; False if charge was denied.
"""
'''try:
type(price) == int or type(price) == float
except ValueError:
print 'Not a number!'
if type(price) != int or type(price) != float:
raise ValueError("Not a number!")
'''
if price < 0:
return False
elif price + self._balance > self._limit:
return False
else:
self._balance += price
return True
def make_payment(self, payment):
"""Process customer payment that reduces balance."""
self._balance -= payment