Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Write a program that simulates flipping a coin N times. Print out tail or head for each flip and let the program count the number

Write a program that simulates flipping a coin N times. Print out tail or head for each flip and let the program count the number of heads.

The player should first choose the number N of coin flips, and then guess the number of heads among them. After the coin flips, a message should be printed that gives the number of heads, and how this compares to the number the player guessed. So, the output of your programme might look something like this:

How often should we flip the coin? 10

How many coin flips will be heads? 4

head head head head head head tail tail head head

Among the 10 coin flips were 8 heads. You guessed there would be 4 heads - your guess was too low!

Make use functions! E.g., use one function that performs a single coin flip (and, e.g., prints head or tail), and then another function that flips the coin N times and returns the number of heads.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_step_2

Step: 3

blur-text-image_step3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Students also viewed these Databases questions