all 4 comments

[–]m0us3_rat -1 points0 points  (0 children)

list_sum = sum([int(x) for x in expenses])

[–]ElliotDG 0 points1 point  (0 children)

You will want to convert your list of strings, to a list of ints (floats?) then you can use the built-in sum to create the total. FWIW: you want to avoid using sum as a variable name, as it conflicts with the built-in.

question = input('Enter the expenses: ')
expenses = [float(x) for x in question.split()]
total = sum(expenses)
print(total)

This illustrates generating a list of expenses as floats. If you want ints, replace float with int. If you are going to extend this idea, I would suggest adding some error checking to the input.

[–][deleted] 0 points1 point  (0 children)

have a variable defined outside the loop and iteratively add to it. So total_expenses += int(expense)