Computer Science, asked by sonalmunot4744, 8 months ago

Using random module, Simulate tossing a coin N times.

Answers

Answered by sapandss
1

Explanation:

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)Read more on Sarthaks.com - https://www.sarthaks.com/133904/using-random-module-simulate-tossing-a-coin-n-times

Answered by PoojaBurra
1

Tossing a coin n times

  • The following programme can be used for the above problem
  • N = input t (“Number of times the coin is tossed”) 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)
  • Execute the program and give the required inputs whether the toss output is head or tail.
  • At the end of execution the total number of heads and tails while tossing a coin would be displayed.

Similar questions