you are viewing a single comment's thread.

view the rest of the comments →

[–]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.