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

4th May 2018, 10:20 AM
Edvin Lysebo
Edvin Lysebo - avatar
4 ответов
+ 2
Thank you, does this mean that «+=» sums up numbers?
4th May 2018, 10:30 AM
Edvin Lysebo
Edvin Lysebo - avatar
+ 1
Try this: import random result = 0 for x in range(10): dicethrow = random.randint(1,6) result += dicethrow print(result)
4th May 2018, 10:28 AM
Ulisses Cruz
Ulisses Cruz - avatar
+ 1
Another way would be: import random result = sum(random.randint(1, 6) for i in range(10)) print(result)
4th May 2018, 10:30 AM
Ulisses Cruz
Ulisses Cruz - avatar
+ 1
Edvin Lysebo what happens is that in every iteration the values of the dicethrow are being 'accumulated' in result.
4th May 2018, 10:33 AM
Ulisses Cruz
Ulisses Cruz - avatar