DEV Community

كريم علي
كريم علي

Posted on

I Need help in python list

So I'm doing a little exercise project witch is supposed to make 100 random head and tails the check for every 6 streaks of head or tail then store it in a variable and repeat this process 10000 times
and I'm stuck at how to make the streaks counting system I have no Idea how to do it and I need help

Top comments (4)

Collapse
 
js402 profile image
Alexander Ertli

Here’s what I thought when I saw your problem:

  1. Make 100 random heads and tails → Maybe using a list comprehension like [random.choice(['H', 'T']) for _ in range(100)]?

  2. Check for every 6-streak of heads or tails and store the results
    → Probably by looping through the list, keeping a counter for consecutive matches, and resetting it when the flip changes.

  3. Repeat this whole thing 10,000 times → So likely a for _ in range(10000): loop that runs the full logic each time.

  4. Print the results → Either the total number of experiments where a 6-streak was found, or the overall probability.

Collapse
 
karim352 profile image
كريم علي

yes but the streak check is the only thing I have no idea how to make

Collapse
 
js402 profile image
Alexander Ertli

here’s a small pattern that might help you think through the streak logic:

for i in range(1, len(flips)):
    current = flips[i]
    previous = flips[i - 1]
Enter fullscreen mode Exit fullscreen mode
  • notice that 1 in range(1, len(flips)) if you don't know what that does it’s worth looking up.

This lets you compare each coin flip to the one before it. Then, you can start tracking how many times the same result appears in a row. That’s your "streak".

From there, think about:

  • When should you increase your streak counter?
  • When should you reset it?
  • What do you want to do when the streak hits 6?
Thread Thread
 
karim352 profile image
كريم علي

thanks for your effort I'll try it and tell you how it went