Budget app Python - transfer method

I am working on the Budget app-project and can’t seem to get my head around some details of the methods:
The Transfer-method should draw an amount from category A and deposit the amount in category B. I want to do this by calling the withdraw and deposit methods in a method ‘transfer’, but I can’t find out how to assign two different categories in this method (category A to withdraw and category B to deposit).
Can anyone explain how this would work?

code so far:

class Category :
	def __init__ (self, categoryname) :
		self.categoryname = categoryname
		self.ledger = list[]
		self.balance = 0

	def deposit(self, amount, description = "") :
		self.ledger.append({"amount" = amount, "description" = description})
		self.balance += amount

	def withdraw(self, amount, description = "") :
		if check_funds = True :
			self.ledger.append({"amount" = -amount, "description" = description})
			self.balance -= amount
			return True
		else : 
			return False

	def transfer (self, amount, categoryname) :
		if check_funds = True : 
			# call withdraw method
			self.withdraw()
			return "Transfer to " ,  categoryname
			# call deposit method
			self.deposit()
			return "Transfer from " ,  categoryname
			
			return True
		else:
			return False

	def check_funds(self, amount) :
		if amount > self.balance :
			return False
		else : 
			return True

You only need one category name, the destination, as the object already has a category name (self.categoryname) for the source that got set when you call the class constructor to get the Category object.

Be careful with that code in transfer(), however. Execution of that method will stop at the first return statement it finds.

2 Likes

Thanks, I used your hints and corrected the other errors ( Python Tutor!) and it works. On with the spend chart…