How do I add the random numbers I have filled a list with?

Viewed 32

I am using a for loop to fill a list with 100 random numbers. I want to add those numbers once the list is complete and I cannot figure out how to do that. I am pretty sure it is something simple that I have just overlooked but it is driving me crazy that I can't get it to work.

2 Answers

Use sum(list)

list = [random.randint(1,9) for i in range(100)]
print(sum(list))

Python has a built in sum function

list_sum = sum(your_list)
Related