{'sm': ['q', 0.25, 1000], 'Bug Out Bag': ['q', 0.25, 100000000]}
Calculate for total amount, here's my code:
single_or_all_total = input('\nDo you want 1 bag or all the bags? (type: 1 for 1 bag, 2 for all bags)\n')
#calculate for a single bag
if int(single_or_all_total) == 1:
single_bag_total = input('\nWhich bag? (e.g. type: small for the "small" bag)\n')
if single_bag_total in coins_in_the_bag:
total = coins_in_the_bag[single_bag_total][1] * coins_in_the_bag[single_bag_total][2]
print('The total for bag {} was {}'.format(single_bag_total, total))
#print(total)
elif single_bag_total not in coins_in_the_bag:
print('Sorry, this was not a valid bag. Please re-run file.')
else:
print('An error occurred, please re-run script.')
#calculate total for all bags
elif single_or_all_total == 2:
total=0
single_bag_total=0
for coin in coins_in_the_bag:
total += coins_in_the_bag[single_bag_total][1] * coins_in_the_bag[single_bag_total][2]
print(total)
the problem is, when I run this, it returns nothing.
I can make my code hit the if int(single_or_all_total) == 1:, but if i input a 2 it doesnt crash at all, it just doesnt return anything.
I'm simply trying to loop through coins_in_the_bag, while adding each value to the total var:
( coins_in_the_bag[single_bag_total][1] * coins_in_the_bag[single_bag_total][2] ) but it is not outputting anything.
What am i doing wrong here?
Updated Error
total += coins_in_the_bag[single_bag_total][1] * coins_in_the_bag[single_bag
_total][2]
UnboundLocalError: local variable 'total' referenced before assignment