+ 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)))
4 Respuestas
+ 10
Great job!
You can write this in the Code Playground and make it public to show other people! 😃👍
+ 8
amazing,thumbs up!!
+ 5
what was missing for "very good"?
+ 4
Nice job!