Scientific Computing with Python Projects - Budget App: Calculating the bar heights

Tell us what’s happening:

Describe your issue in detail here.
Hello there,
I pass all the tests except for one, and that has to do with me misunderstanding a part of the task description regarding the bar heights. It says: "The percentage spent should be calculated only with withdrawals and not with deposits. " I calculate the bar height via the following “algorithm”:

  1. take the first ledger-entry for a certain category as this one has to the only deposit of interest (there must be a positive number to subtract withdrawals from)
  2. for the rest of the ledger, add all the negative numbers that make up the sum of all withdrawals
  3. divide the number of 1) by the result of 2).
    Unfortunately, my resulting bars do not match the expected ones so there must be a misunderstanding regarding the task description

Your code so far

Here is the corresponding code snippet:

# adding all withdrawals and storing the results in a list
withdrawals_list = []
for elem in categories:
      sum_withdrawals = 0
      for elem2 in eval("elem"+".ledger"):
           for elem3, value in elem2.items():
                if type(value) == str:
                     continue  # the "description entry is of no interest"
                elif value < 0:
                     sum_withdrawals = sum_withdrawals + value
      withdrawals_list.append(sum_withdrawals)

# storing all initial deposits in a list
list_of_initial_deposits = list()
for elem in categories:
      for elem2, value in eval("elem"+".ledger")[0].items():
           if type(value) == str:
                continue
           if value > 0:
                list_of_initial_deposits.append(value)

# calculating the ratios and formatting the results                     
ratios_list = []
for i in range(0, len(withdrawals_list)):
      ratios_list.append(100* abs(withdrawals_list[i]) / list_of_initial_deposits[i])

ratios_list = [ int(math.floor(x / 10.0)) * 10 for x in ratios_list] 

Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/115.0

Challenge Information:

Scientific Computing with Python Projects - Budget App

It’s really confusing but you’re close to it here.

take the first ledger-entry for a certain category as this one has to the only deposit of interest

It says not to use deposits, but you are using deposits to calculate. What it means is to calculate the withdrawals of each category as a percentage of the total withdrawals of all categories (not as a percentage of the deposit)

https://forum.freecodecamp.org/t/scientific-computing-with-python-projects-budget-app/619185/4?u=pkdvalis

1 Like

Hi,
thank you very much for your quick and easy-to-understand reply!

1 Like

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