0

Hello I need help with combining lists where I am given two lists of costs from 2017 and 2018, to combine them into a single list called combined_costs and then calculate the sum of the costs from 2017-2018 called total_costs.

costs_2017 = [1300, 1500, 1360, 1789, 611]

costs_2018 = [1545, 789, 913, 8854, 462]

I figured out how to do the combined_costs:

combined_costs = cost_2017 + cost_2018

len(combined_costs)

But as for total_costs, I'm not sure if I am heading in the right direction but this is all I have for total_costs:

total_costs = combined_costs

anj_M1
  • 19
  • 2
  • It sounds like you want `total_costs = sum(combined_costs)` - a single sum of the values in the combined list. – tdelaney Feb 21 '23 at 00:20
  • 2
    You have all the right words in your question for a search. You could probably find this faster by googling something like "python sum list" – Code-Apprentice Feb 21 '23 at 00:23
  • 1
    the docs here are especially helpful around builtin functions https://docs.python.org/3/library/functions.html ! – ti7 Feb 21 '23 at 00:24

1 Answers1

0

If you are looking for a sum then:

total_costs = sum(combined_costs)

which is:

19123
Allan Wind
  • 23,068
  • 5
  • 28
  • 38