-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathcustomer.py
More file actions
98 lines (84 loc) · 3.23 KB
/
customer.py
File metadata and controls
98 lines (84 loc) · 3.23 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
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
import random
class Customer:
""" This is a class that manages customers"""
account_types = {'S': 'Savings', 'C': 'Current', 'YS': 'Youth Savings'}
act_no_prefix = {'S': 1441, 'C': 1442, 'YS': 1443}
def __init__(self, name, age=None):
self.name = name
self.age = age
self.account_type = str()
self.account_number = None
self.balance = float()
# Setters
def set_name(self, name):
"""Sets customer's name. Takes name as an input"""
self.name = name
def set_age(self, age):
"""Sets customer's age. Takes age as an input"""
self.age = age
# Getters
def get_name(self):
"""Returns customer's name. Takes no input"""
return self.name
def get_age(self):
"""Returns customer's age. Takes no input"""
return self.age
def get_balance(self):
"""Returns customer's account balance"""
if self.account_number:
return {'balance': self.balance}
else:
return {'balance': 'You have no account records'}
def get_account_details(self):
"""Returns customer's account type and account number"""
return {
'name': self.name,
'account_type': self.account_type,
'account_number': self.account_number,
'balance': self.balance,
}
def create_account(self):
"""Creates an account for the customer."""
print(self.account_types)
act_type = input("Enter the appropriate abbreviation for your Account Type: ").strip().upper()
self.account_type = self.account_types[act_type]
acctno = str(self.act_no_prefix[act_type])
for i in range(10):
acctno += str(random.randint(0,9))
self.account_number = acctno
return {
'message': 'Account created successfully',
'account': self.account_number
}
def deposit(self, amount):
"""Credits a customer's account with amount. Takes amount as input."""
if self.account_number:
self.balance += amount
return {
'message': f'Deposited Gh¢{float(amount)}',
'account': self.account_number,
'balance': self.balance,
}
else:
print("Create Account to Deposit")
self.create_account()
return self.deposit(amount)
def withdraw(self, amount):
"""Debits a customer's account with amount. Takes amount as input"""
if self.account_number:
if self.balance >= amount:
self.balance -= amount
return {
'message': f'Withdrawn {amount}.00',
'account': self.account_number,
'balance': self.balance
}
else:
return {'message':f"You can only withdraw a maximum of Gh¢{self.balance}"}
else:
print("You do not have an account")
create = input("Create a new account? (Y/N): ").strip().lower()
if create == 'y':
return self.create_account()
else:
return {'message': 'We are here to assist whenever you are ready to create your account'}