I am trying to learn Python and I am writing a few scripts for fun to get used to the language.
I am trying to create a script that will roll 3 'dice' and if all 3 return 6, it will write it to a list, otherwise roll again and update the counter.
All this is supposed to happen a large amount of times, so that I can get a large list and then calculate the average amount of rolls needed to get triple 6.
After many iterations this is my code right now (probably sub-optimal since I edited it a lot to try and find a way for it to work)
#!/usr/bin/python
from random import randint
first = randint(0,5)
second = randint(0,5)
third = randint(0,5)
count = 1
list = []
for_list = range(10000)
for item in for_list:
while first != 5 or second != 5 or third != 5:
count+=1
first = randint(0,5)
second = randint(0,5)
third = randint(0,5)
if first == 5 and second == 5 and third == 5:
list.append(count)
count = 1
print sum(list) / float(len(list))
print list
Right now it seems like the while loop works, but I cant figure out how to get it to actually run many times (the for loop, in this example 10,000 times).
This is my output (prints "average" and the list, containing the count variable:
218.0
[218]
So in this run it took 218 rolls. After that the script ends. Can anyone help me understand why the script isn't running the for loop?
Thanks!
forloop start, then? The code above looks valid to me.whilecondition is always going to be false after the first match.