Need help on budget App

Hi, I need help with this TypeError, it keeps returning this error when I run the program.

In particular, this code below:

def transfer(self, amount, category_2):

        if self.check_funds(amount):

            self.withdraw(f"{amount} Transfer to {category_2.category}")

            category_2.deposit(f"{amount} Transfer from {self.category}")

            # self.withdraw(amount, "Transfer to " + category_2.category)

            # category_2.deposit(amount, "Transfer from " + self.category)

            return True


            return False

When I use the commented code, the program functions normally. I suspect that it’s supposed to have three values, but in my f-string, I’ve only provided two values, which is amount and category. How do I convert the commented ones into f-string?

Name of Challenge: Budget App

Link to Challenge:

1 Like

Shouldn’t withdraw and deposit methods receive two arguments? The example with f-strings passes just one argument - the whole string.

ohh, I didn’t know that, I thought the f-string is returning 2 values because there are two braces. Is it possible to even use f-string in this?

It’s a bit the other way around, because there are two braces, then two values will be put into the string. And yes, f-string can be used here just for the second argument.

1 Like

Sorry, I don’t quite understand what do you mean by two values were put into the string. If there are two values in that f-string, then how is it passing only one argument? Or is it two values in one argument?

1 Like

Taking for example:

val1 = 15
val2 = 11
s = f'{val1} and {val2}'

Then the s is a single string - '15 and 11'. One f-string results in a one string.


Ahh I see. So in short, it is possible but it will just reduce the readability then since regardless of how many values in the f-string, if only 1 f-string exist, then it’s only returning one argument then. I’ll just stick to the commented code since it’s much more understandable.

1 Like

Well, I think it comes down to the preference which one of the below is more readable. But in example with rather limited scope the difference won’t be big.

self.withdraw(amount, f"Transfer to {category_2.category}")
self.withdraw(amount, "Transfer to " + category_2.category)

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