Tell us what’s happening:
Describe your issue in detail here.
In this project, I get a problem for the creat_spend_chart function.
The explaination isn’t clear, I don’t understand it pass the list [‘Food,Clothing,Auto’] or only Food.ledger as an argument
Your code so far
class Category:
def __init__(self,category):
self.category = category
self.ledger = []
def __str__(self):
title = f"{self.category:*^30}\n"
items =''
Total=0
for item in self.ledger:
items += f"{item['description'][:23]:23}"+f"{item['amount']:>7.2f}"+'\n'
Total += item['amount']
output = title+items+'Total: '+f'{Total:.2f}'
return output
def deposit(self,amount,description=''):
if description is None:
self.ledger.append({"amount": amount, "description": ' '})
else:
self.ledger.append({"amount": amount, "description": description})
def withdraw(self,amount,description=''):
if self.check_funds(amount):
if description is None:
self.ledger.append({"amount": -amount, "description": ' '})
return True
else:
self.ledger.append({"amount": -amount, "description": description})
return True
else:
return False
def get_balance(self):
balance=0
for item in self.ledger:
balance +=item['amount']
return balance
def transfer(self,amount,category):
if self.check_funds(amount):
self.withdraw(amount,f'Transfer to {category.category}')
category.deposit(amount,f'Transfer from {self.category}')
return True
else:
return False
def check_funds(self,amount):
if amount <= self.get_balance():
return True
if amount >=self.get_balance():
return False
def create_spend_chart(categories):
total_cost =0
category_list=[]
percent_list=[]
y_bar=100
chart ='Percentage spent by category\n'
for item in categories:
if item['amount']<0:
category_list.append(item['description'])
total_cost+=(-item['amount'])
x_bar = len(category_list)
for item in categories:
if item['amount']<0:
result = ((-item['amount'])-(-item['amount'])%10)/10*10
percent_list.append(result)
for y in range(y_bar,-1,-10):
line =f'{y:>3}| '
for x in range(x_bar):
if percent_list[x]>= y:
line+= 'o '
else:
line+=' '
chart += line+'\n'
bottom_line = ' -'
for x in range(x_bar):
bottom_line +='---'
chart += bottom_line +'\n'
for H in range(23):
bottom_description=' '
for x in range(x_bar):
charg = 23-len(category_list[x])
if charg>=0:
category_list[x]+= ' '*charg
bottom_description += f'{category_list[x][H]} '
chart += bottom_description +'\n'
return chart
Your browser information:
User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/122.0.0.0 Safari/537.36
Challenge Information:
Scientific Computing with Python Projects - Budget App