Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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):

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

Once weve built a class, if we decide we need some sort of specialized functionality, we can create a new class that inherit 

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]}

Step by Step Solution

3.50 Rating (153 Votes )

There are 3 Steps involved in it

Step: 1

I have prepared the required python code for you I have tested the code against the test cases and i... blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Cost Accounting A Managerial Emphasis

Authors: Charles T. Horngren, Srikant M.Dater, George Foster, Madhav

13th Edition

8120335643, 136126634, 978-0136126638

More Books

Students also viewed these Accounting questions

Question

How can a management accountant help formulate a strategy?

Answered: 1 week ago