+ 6

Fair Coin Toss

This is the answer to one of my homework questions to create a function seq_sum that will simulate a fair coin toss n times and yield the number of heads. Im getting good at this! import random def seq_sum(n): heads = 0 for i in range(n): coin = random.randint(0,1) if coin == 1: heads += 1 yield 1 elif coin == 0: yield 0 print(heads) print(list(seq_sum(25)))

11th Nov 2017, 4:48 AM
Heather Moseley
Heather Moseley - avatar
5 Answers
+ 12
Can't wait to see what's next 🙂
11th Nov 2017, 5:08 AM
Ace
Ace - avatar
+ 10
Great job! You can write this in the Code Playground and make it public to show other people! 😃👍
11th Nov 2017, 4:49 AM
Learnsolo
+ 8
amazing,thumbs up!!
11th Nov 2017, 4:53 AM
᠌᠌Brains[Abidemi]
᠌᠌Brains[Abidemi] - avatar
+ 5
what was missing for "very good"?
11th Nov 2017, 9:16 AM
Oma Falk
Oma Falk - avatar
+ 4
Nice job!
11th Nov 2017, 4:58 AM
John Wells
John Wells - avatar