class Budget: def __init__(self, income): self.income=income self.expenses = 0 self.categories={} def get_income(self): print('Your current income is %i
Fantastic news! We've Found the answer you've been seeking!
Question:
class Budget:
def __init__(self, income):
self.income=income
self.expenses = 0
self.categories={}
def get_income(self):
print('Your current income is %i dollars' ,self.income)
def add_expense(self,category,limit):
self.categories[category]=limit
self.expenses+=limit
def check_budget(self):
print('Income is ',self.income,' dollars ')
print('Expenses total',self.expenses,' dollars ')
amountRemaining=self.income-self.expenses
if amountRemaining>0:
print('You are at or under budget.', 'You have ',amountRemaining,'dollars remaining')
else:
print('You are ','amountRemaining,' ,'dollars over budget.' ,'Adjust your expenses')
def adjust_income(self,adjustment):
income+=adjustment
Transcribed Image Text:
Once we've built a class, if we decide we need some sort of specialized functionality, we can create a new class that inherits all of the properties of the first one Let's do that now! V Question 3.2.1 (4 points): Now that you have a functioning class, your next task is to create a second class, EnhancedBudget , that inherits the Budget class. You should create this new class in the same budget. py script. When you're done, there should be two different classes available to be imported from the script: Budget and EnhancedBudget. In this new EnhancedBudget class, do the following: • add a new class attribute, transactions . This should be initialized when the EnhancedBudget is created and should default to being an empty dictionary ( {} ). This dictionary will have budget categories as its keys and the values associated with each key will be a list of the transactions (in dollars) logged for that category. • add a new class method, 1og_transaction , that takes two inputs: category and amount . Using these two inputs, this method should for the following: 1. Check to see if the provided category is already in the transactions dictionary. 2. If it is, it should append the amount to the list of amounts that already exist in that category. 3. If it isn't already in the transactions dictionary, it should create a new list associated with that category key with the amount as the first entry in th list. With this new attribute and this new method, you should be able to log transactions in your new enhanced budget object! In order to see if your code is working, run the following cell. If everyting is set up correctly, it should output the following: Income is 2000 dollars. Expenses total 1100 dollars. You are at or under budget. You have 900 dollars remaining. Transaction Log: {'Food' : [7, 12. 5], 'Rent': [750], 'Utilities' : [20, 55]} Once we've built a class, if we decide we need some sort of specialized functionality, we can create a new class that inherits all of the properties of the first one Let's do that now! V Question 3.2.1 (4 points): Now that you have a functioning class, your next task is to create a second class, EnhancedBudget , that inherits the Budget class. You should create this new class in the same budget. py script. When you're done, there should be two different classes available to be imported from the script: Budget and EnhancedBudget. In this new EnhancedBudget class, do the following: • add a new class attribute, transactions . This should be initialized when the EnhancedBudget is created and should default to being an empty dictionary ( {} ). This dictionary will have budget categories as its keys and the values associated with each key will be a list of the transactions (in dollars) logged for that category. • add a new class method, 1og_transaction , that takes two inputs: category and amount . Using these two inputs, this method should for the following: 1. Check to see if the provided category is already in the transactions dictionary. 2. If it is, it should append the amount to the list of amounts that already exist in that category. 3. If it isn't already in the transactions dictionary, it should create a new list associated with that category key with the amount as the first entry in th list. With this new attribute and this new method, you should be able to log transactions in your new enhanced budget object! In order to see if your code is working, run the following cell. If everyting is set up correctly, it should output the following: Income is 2000 dollars. Expenses total 1100 dollars. You are at or under budget. You have 900 dollars remaining. Transaction Log: {'Food' : [7, 12. 5], 'Rent': [750], 'Utilities' : [20, 55]}
Expert Answer:
Answer rating: 100% (QA)
I have prepared the required python code for you I have tested the code against the test cases and i... View the full answer
Posted Date:
Students also viewed these accounting questions
-
Under the current rate method, all the expenses are translated using some form of current-period exchange rate. Under the temporal method, some expenses such as salaries and utilities are translated...
-
You are traveling abroad and have only American dollars with you. You are currently in the capital but you will soon be heading out to a small town for an extended stay. In the town, no one takes...
-
You are on your way to an important budget meeting. In the elevator, you review the project valuation analysis you had your summer associate prepare for one of the projects to be discussed: Looking...
-
The standard manufacturing process for thin-film resistors produces resistors with an average of 1k and a standard deviation of 3.5 Q. Twenty samples of a new process were tested, and the data can be...
-
After working as a consultant for the "We Can Help You" firm for seven years, you recently received a promotion to manager. In this new role, you report to a partner and are responsible for various...
-
Identifying cash inflows and outflows Required Indicate which of the following items will result in cash inflows and which will result in cash outflows. The first one is shown as an example. Item...
-
Suppose electrons move through a copper wire at speed \(v\). Call the linear charge densities in the Earth reference frame \(\lambda_{E_{p}}\) for the fixed positive ions in the wire and...
-
Steven Truck Company has been an 80%-owned subsidiary of Paulz Heavy Equipment since January 1, 2013, when Paulz acquired 128,000 shares of Steven common stock for $832,000, an amount equal to the...
-
(a) An investor purchased 300 units of a Mutual Fund at Rs. 12.25 per unit on 31 December, 2009. As on 31st December, 2010 he has received Rs. 1.25 as dividend and Rs. 1.00 as capital gains...
-
Robert takes loan of $14k to buy a truck and seller is offering a uniform series of payment at 6.5% interest for 5 years. Calculate the monthly payment that Robert has to pay to buy that truck
-
How has the operational relationship between the U.S. intelligence community evolved since 2015?
-
A narrative description of products, services, or results to be delivered by the project is a/an: a. request for information b. business case c. project statement of work d. elevator pitch
-
When might consensus be the best decisionmaking strategy?
-
If more than one parent company is involved in a project, why is it important for the project manager to understand the culture of each?
-
What are the five stages of team development?
-
On most small to medium-sized projects, how many intermediate milestones should be identified in the charter?
-
1. Visualising the process of turning potential customers into customers from the marketer's perspective is The marketing funnel The consumer decision-making process The customer journey Target...
-
Read the case study Richter: Information Technology at Hungarys Largest Pharma and answer the following question: How does the organization ensure the accuracy of the data it stores?
-
Two radio stations have the same power output from their antennas. One broadcasts AM at a frequency of \(1000 \mathrm{kHz}\) and one broadcasts FM at a frequency of \(100 \mathrm{MHz}\). Which...
-
A paramecium is covered with motile hairs called cilia that propel it at a speed of \(1 \mathrm{~mm} / \mathrm{s}\). If the paramecium has a volume of \(2 \times 10^{-13} \mathrm{~m}^{3}\) and a...
-
How many photons does a \(5.0 \mathrm{~mW}\) helium-neon laser \((\lambda=633 \mathrm{~nm})\) emit in 1 second? A. \(1.2 \times 10^{19}\) B. \(4.0 \times 10^{18}\) C. \(8.0 \times 10^{16}\) D. \(1.6...
Study smarter with the SolutionInn App