MENU
Question -

Using random module, Simulate tossing a coin N times.



Answer -

N = input (“Number of tossing a coin”) from random import choice
heads = 0
tails = 0
coin = [‘head’, ‘tail’]
for n in range (N) :
toss = choice (coin)
if toss = ‘head’ :
heads = heads + 1
if toss = = ‘tail’ :
tails = tails + 1
print (‘Heads:’, heads)
print (‘Tails:’, tails)

Comment(S)

Show all Coment

Leave a Comment

Free - Previous Years Question Papers
Any questions? Ask us!
×