-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbudget1.py
188 lines (126 loc) · 6.76 KB
/
budget1.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
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
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
"""
Creating a budget app using classes and objects. Got hooked defining the transfer method
"""
class Budget:
def __init__(self, category, balance):
self.category = category
self.balance = balance
def deposit(self):
userDeposit = int(input("How much would you like to deposit?: "))
self.balance += userDeposit
if userDeposit > 1000:
print("Deposit successful! \nCurrent Balance for", self.category, "is", self.balance)
else:
print("Input a valid amount")
def withdrawal(self):
userWithdrawal = int(input("How much would you want to withdraw?: "))
if userWithdrawal <= self.balance:
self.balance -= userWithdrawal
print("Withdrawal successful \nYour current balance for", self.category, "is", self.balance)
else:
print("Insufficient funds! Try again")
def check_balance(self):
print(f"Your current balance for {self.category} is {self.balance}")
def transfer(self, category):
withdrawFrom = input("What category would you want to transfer from?: ")
amountTransfer = int(input("How much would you want to transfer? "))
if withdrawFrom in ["Food", "Clothing", "Housing", "Personal Care", "Data", "Transportation"] and amountTransfer <= self.balance:
self.balance -= amountTransfer
print(f"Your current balance for {self.category} is {self.balance}")
# transferTo = input("What category would you want to tranfer to?: ") still unsure about this??
category.balance += amountTransfer
print(f"Current balance for {category.category} is {category.balance}, transfer successful!")
else:
print("Please select a valid category!")
"""
Still struggling to understand the concept of objects and how you can manipulate their parameters. I'll do more research and update my code on this budget app
subsequently. I understand my codes are sort of everywhere at the moment, but I'll sure get better. What follows is a way of testing my codes, however I know
this is not the proper way to do it but I'll learn that too.
"""
foodBudget = Budget("Food", 5000)
housingBudget = Budget("Housing", 0)
clothingBudget = Budget("Clothing", 1500)
personalCareBudget = Budget("Personal Care", 0)
dataBudget = Budget("Data", 0)
transportationBudget = Budget("Transportation", 0)
database = {
'Budcustomer': ['Elon', 'Musk', '2222', '[email protected]' ]
}
print("=" * 60)
import time
print(" ~~~~~~~~~~~ WELCOME TO BUGETTI ~~~~~~~~~~~")
print("Today is a good day to budget your earnings, login to get started!")
time.sleep(2)
print(" >>>> Input your details to login <<<< ")
userIdFromUser = input("UserID: ")
passwordFromUser = input("Password: ")
for userId, userDetails in database.items():
if(userId == userIdFromUser) and (userDetails[2] == passwordFromUser):
print("Hello {}, what would you want to do today? Select an option to begin.".format(database['Budcustomer'][0]))
print("1. Deposit")
print("2. Withdrawal")
print("3. Transfer")
print("4. Check Balance")
print("These are the available categories: \n-Food \n-Clothing \n-Housing \n-Personal Care \n-Data \n-Transportation")
userSelection = int(input("Select an option: "))
print("=" * 60)
if(userSelection == 1):
userCategory = input("What Budget category would you want to deposit into? ")
if userCategory in ["food", "Food"]:
foodBudget.deposit()
print("Thanks for using Budgetti")
elif userCategory in ["cloth", "Cloth", "Clothing", "clothing"]:
clothingBudget.deposit()
print("Thanks for using Budgetti")
elif userCategory in ["housing", "rent", "Housing", "Rent"]:
housingBudget.deposit()
print("Thanks for using Budgetti")
elif userCategory in ["Personal Care", "personal care", "Personal care", "personal Care"]:
personalCareBudget.deposit()
print("Thanks for using Budgetti")
elif userCategory in ["Transportation", "transportation"]:
transportationBudget.deposit()
print("Thanks for using Budgetti")
elif userCategory in ["Data", "data"]:
dataBudget.deposit()
print("Thanks for using Budgetti")
else:
print("You have chosen an invalid category!")
elif userSelection == 2:
userCategory = input("What Budget category would you want to witdraw from? ")
if userCategory in ["food", "Food"]:
foodBudget.withdrawal()
elif userCategory in ["cloth", "Cloth", "Clothing", "clothing"]:
clothingBudget.withdrawal()
elif userCategory in ["housing", "rent", "Housing", "Rent"]:
housingBudget.withdrawal()
elif userCategory in ["Personal Care", "personal care", "Personal care", "personal Care"]:
personalCareBudget.withdrawal()
elif userCategory in ["Transportation", "transportation"]:
transportationBudget.withdrawal()
elif userCategory in ["Data", "data"]:
dataBudget.withdrawal()
else:
print("You have selected an invalid category!")
elif userSelection == 3:
foodBudget.transfer(clothingBudget)
elif userSelection == 4:
userCategory = input("What Budget category would you want to check for balance? ")
if userCategory in ["food", "Food"]:
foodBudget.check_balance()
elif userCategory in ["cloth", "Cloth", "Clothing", "clothing"]:
clothingBudget.check_balance()
elif userCategory in ["housing", "rent", "Housing", "Rent"]:
housingBudget.check_balance()
elif userCategory in ["Personal Care", "personal care", "Personal care", "personal Care"]:
personalCareBudget.check_balance()
elif userCategory in ["Transportation", "transportation"]:
transportationBudget.check_balance()
elif userCategory in ["Data", "data"]:
dataBudget.check_balance()
else:
print("You have chosen an invalid category!")
else:
print("Please select a valid option, try again!")
else:
print('Invalid account or password')