0

In trying to create a simple budgeting tool for practice, I cannot access my bill_list dictionary sum.

Variable "total_monthly_bills" stays at 0.00 no matter what I do. Code is below. This is just a snippet of my code where I believe the issue is. total_monthly_bills is defined at module level. https://code.sololearn.com/cAXPDWf716v7/?ref=app

21st Sep 2020, 1:30 PM
Tyler Harvey
Tyler Harvey - avatar
8 odpowiedzi
+ 2
Check your report function. Where you want to print <total_monthly_bills> you are printing instead <bill_account_balance>.
21st Sep 2020, 5:04 PM
Ipang
+ 6
I found an issue in a variable name. - in function change_bill_list in the last line you calculate the sum of all bills and store it to total_monthly_bills. But this variable is never used. Instead of this, you use bill_account_balance, which has a value of 0 in report function. change the last line in report function, and this issue should be fixed. def change_bill_list(): global total_monthly_bills global bill_list bill_name = input("Enter the name of this bill:\n\n") bill_cost = float(input("How much is this bill, monthly?\n\n")) bill_list[bill_name] = bill_cost total_monthly_bills = sum(bill_list.values()) def report(): print("\nYour total monthly income is: " + str(total_monthly_income)) print("Your weekly bill allowance is: " + str(weekly_bill_allowance)) print("Your totally monthly bills come to: " + str(total_monthly_bills)) #print("Your totally monthly bills come to: " + str(bill_account_balance))
21st Sep 2020, 5:25 PM
Lothar
Lothar - avatar
+ 2
Post edited with link to code
21st Sep 2020, 4:32 PM
Tyler Harvey
Tyler Harvey - avatar
+ 2
Thank you! That was the problem. bill_account_balance is a variable that I am going to implement but haven't yet..I must have mismatched it with total_monthly_bills
22nd Sep 2020, 4:28 AM
Tyler Harvey
Tyler Harvey - avatar
+ 1
Thank you for your understanding 👍 I will look into it, but even if I can't respond immediately, I'm pretty sure someone will. Quite a lot of people here are good with Python.
21st Sep 2020, 4:37 PM
Ipang
0
Did you call `change_bill_list`? this seems to work ... total_monthly_bills = 0 bill_list = {} def change_bill_list(): global total_monthly_bills # assumed float global bill_list # assumed dictionary bill_name = input("Enter the name of this bill:") bill_cost = float(input("How much is this bill, monthly?")) bill_list[bill_name] = bill_cost total_monthly_bills = sum(bill_list.values()) change_bill_list() # call change_bill_list print(total_monthly_bills, bill_list)
21st Sep 2020, 2:59 PM
Ipang
0
Still not working...I run my program, input the bill name and amounts, and run the report function, and total_monthly_bills still come out to 0.0. I did make sure to call the functions. I would post entire module here but I don't have enough room. Here is that function again: def change_bill_list(): global total_monthly_bills global bill_list bill_name = input("Enter the name of this bill:\n\n") bill_cost = float(input("How much is this bill, monthly?\n\n")) bill_list[bill_name] = bill_cost total_monthly_bills = sum(bill_list.values()) here is my report function: def report(): print("\nYour total monthly income is: " + str(total_monthly_income)) print("Your weekly bill allowance is: " + str(weekly_bill_allowance)) print("Your totally monthly bills come to: " + str(bill_account_balance))
21st Sep 2020, 4:15 PM
Tyler Harvey
Tyler Harvey - avatar
0
You can save your code in SoloLearn, then share the saved code link instead of posting it in raw text format. Here's how you can do that 👇 https://www.sololearn.com/post/75089/?ref=app
21st Sep 2020, 4:19 PM
Ipang