Jul-12-2020, 01:25 PM
You need to assign x to a value first. Try:
xs = [12, 14, 10] x = 0 for num in xs: x += num print(x)Or you can just use the sum function:
xs = [12, 14, 10] x = sum(num for num in xs) print(x)