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”:
- 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)
- for the rest of the ledger, add all the negative numbers that make up the sum of all withdrawals
- 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