0
Python dice simulator "int object is not iterable"
So, I am trying to make a dice simulator simulates 10 throws, and then sum the numbers of the throws. I am struggling with the sum part, "int object is not iterable". https://code.sololearn.com/c2A1rW8395g7/?ref=app
4 Antworten
+ 2
Thank you, does this mean that «+=» sums up numbers?
+ 1
Try this:
import random
result = 0
for x in range(10):
dicethrow = random.randint(1,6)
result += dicethrow
print(result)
+ 1
Another way would be:
import random
result = sum(random.randint(1, 6) for i in range(10))
print(result)
+ 1
Edvin Lysebo
what happens is that in every iteration the values of the dicethrow are being 'accumulated' in result.