I am new at python and is really confused of how loop, range, and sum work...
# Input
x = int(input("Number of pages: "))
y = int(input("Random value: "))
# Operasi
for result in range(0, x + y, y):
ones = result % 10
print(sum(ones))
This is the code I wrote earlier, what I am trying to achieve is: "This time, Mr. Rizz made a calculation on the pages of the course book he had. He will choose a random value for one book. Next, Mr. Rizz will add up all the ones number in total pages that can be divided by the random value." (e.g if x = 12 and y = 2 then range should be [0, 2, 4, 6, 8, 0, 2])
Now, how do I sum up all the values I got in range? It always say that it is not iterable. sorry English isn't my first language, feel free to ask if there's any confusion
Using your code as a starting point, you likely want to accumulate a total in a variable:
Alternatively, if you want to use this definition of
range()withsum()you can try: