Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit a202e49

Browse files
committed
coin flip streaks v2
1 parent 4ce3789 commit a202e49

File tree

1 file changed

+4
-5
lines changed

1 file changed

+4
-5
lines changed

‎coin_flip_streaks.py‎

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ def streak_tracker(flips_list=[], streak_of=3):
4949
that displays how many of each type of streak occurred.
5050
"""
5151
STREAKS = {'HEADS': 0, 'TAILS': 0} # Keep a dictionary to track counts.
52-
HEAD_STREAKS, TAIL_STREAKS = (0, 0) # Keep track of the type of streak and how many.
52+
HEAD_STREAKS, TAIL_STREAKS = (0, 0) # Keep track of the type of streak and how many.
5353

5454
if (flips_list != []): # CASE: Nonempty list
5555
previous = None
@@ -69,14 +69,13 @@ def streak_tracker(flips_list=[], streak_of=3):
6969
elif (current=='T'):
7070
STREAKS['TAILS'] += 1
7171
# CASE: Different than previous value
72-
else:
72+
elif (current!=previous):
7373
if (current=='H'):
7474
STREAKS['HEADS'] = 1
7575
elif (current=='T'):
7676
STREAKS['TAILS'] = 1
7777

78-
previous = flips_list[i-1] # Store current as previous for next iteration
79-
78+
previous = flips_list[i] # Store current as previous for next iteration
8079
return {'HEAD STREAKS': HEAD_STREAKS, 'TAIL STREAKS': TAIL_STREAKS}
8180

8281
else: # CASE: Empty list
@@ -86,7 +85,7 @@ def streak_tracker(flips_list=[], streak_of=3):
8685

8786
# TESTS COMMENTED BELOW:
8887
'''
89-
coin_flip_results = coin_flips(10000)
88+
coin_flip_results = coin_flips(1000)
9089
print(' '.join(coin_flip_results))
9190
9291
sample = [ 'H', 'H', 'T', 'H', 'T', 'H', 'H', 'T', 'H', 'H', 'T', 'T', 'T', 'H', 'H', 'T', 'T', 'T', 'H', 'T', 'H', 'T', 'H', 'H', 'T',

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /