Help Wanted for Budget App

Hello,

Tell us what’s happening:
I am having trouble generating the check_funds method for the budget class. Based on the error message there seems to be a type error but I am out of my wits in terms of how to go about fixing this. The error message is the following:

Traceback (most recent call last):
File “main.py”, line 12, in
food.transfer(50, clothing)
File “/home/runner/fcc-budget-app/budget.py”, line 21, in transfer
if self.check_funds(amount):
File “/home/runner/fcc-budget-app/budget.py”, line 26, in check_funds
if amount > self.balance:
TypeError: ‘>’ not supported between instances of ‘Category’ and ‘float’

Will be grateful for any help that I can get here…

Your code so far
https://repl.it/@ariyosh/fcc-budget-app#budget.py

Your browser information:

User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/88.0.4324.96 Safari/537.36.

Challenge: Budget App

Link to the challenge:

Hey I check your code and I think the problem is with the position of your arguments on the transfer() method
This is your code:

def transfer(self, category2, amount):
if self.check_funds(amount):
self.withdraw(amount, description = ‘Transfer to {}’.format(category2.name))
category2.deposit(amount, description = ‘Transfer from {}’.format(self.name))

Try this instead:

def transfer(self, amount, category2):
if self.check_funds(amount):
self.withdraw(amount, description = ‘Transfer to {}’.format(category2.name))
category2.deposit(amount, description = ‘Transfer from {}’.format(self.name))

Thank you so much! That seemed to have solved the issue. I did not know that there was a rule for argument positions. Is there a good resource on this that I could look into?

There are two rules:
First, a function needs to start with positional arguments (those without default values) and after that those with default-values.
Second: declare positional values in the same order they are called

The testing module calls transfer(value, category) - so you broke rule two declaring transfer(self, category, value).

1 Like

Ohhh I see. Thank you so much for your help! I will keep that in mind.

I made a slight mistake in the second rule - order of arguments is only relevant on positional arguments (hence they are called “positional”).

The others can be called in any order BUT you have to use their names - but you can also not call the at all.
For example this works:

def function(x, y, color="red", name="Bob", age="12"):
    ....

function(5, 7, name="Fred", color="blue")

Gotcha. Thank you Jagaya. I found this in a stackoverflow conversation that was also quite helpful.

Positional arguments are arguments that can be called by their position in the function definition.
Keyword arguments are arguments that can be called by their name.
Required arguments are arguments that must passed to the function.
Optional arguments are argument that can be not passed to the function. In python optional arguments are arguments that have a default value .

1 Like

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.