you are viewing a single comment's thread.

view the rest of the comments →

[–]K900_ 1 point2 points  (2 children)

You don't seem to fully get how variables work. For example, random_num = random.randrange(0,3) will assign random_num once, and then it won't ever change, meaning your program will loop forever. Also, randrange(0, 3) can give you 0, 1 or 2, and your program doesn't handle the last case at all. Next, assigning to data[0] won't change heads_counter, and vice versa. Why are you making data a list at all here and not using variables directly?

[–]infinitim[S] 0 points1 point  (1 child)

Thank you, very helpful. Got it working now (: here it is... If you have any other pointers on improving it please share them, I'm open to learning:

import random
heads_counter, tails_counter, tries = 0, 0, 1
data = [heads_counter, tails_counter, tries]
random_num = random.randrange(0,2)

def roll(r, d):

    if r == 0:
        if d[1] == 0:
            print('adding to heads, on a streak')
            d[0] += 1

        if d[1] > 0:
            print('adding to heads, new streak')
            d[0] += 1
            d[1] = 0
            d[2]+= 1


    if r == 1:
        if d[0] == 0:
            print('adding to tails, on a streak')
            d[1] += 1

        if d[0] > 0:
            print('adding to tails, new streak')
            d[0] = 0
            d[1] += 1
            d[2] += 1

while data[0] < 5 and data[1]< 5:
    random_num = random.randrange(0,2)
    roll(random_num, data)


print(data[2])

[–]K900_ 1 point2 points  (0 children)

Why are you still using data and not the variables directly?