Digital Solutions

 Challenge 01 - Heads or Tails 

Generate the random outcome of flipping a coin using Python. Use the letter 'H' for Heads, and the letter 'T' for Tails.

Your output could look like this:


Or it could look like this:


 Challenge 02 - Quit on Tails 

Simulate the flipping of the coin until I throw a 'T' (Tails).

Your output could look like this:


It could also look like this:


 Challenge 03 - Counting the Flips 

Let a user enter an integer that is used to determine the number of coin flips you program will make.

So if the user enters 20, your code will simulate 20 coin flips. At the end of your program, it will display a summary of the frequency of Heads ('H') and Tails ('T') that were flipped.

So when starting your program, you might chose to code it like this:

import random target_flips = int(input("Enter number of flips: ")) total_flips = 0 #declare any other variables here while total_flips < target_flips: #your code here total_flips += 1

Your program might look like this when it is run:

Enter number of flips: 11 T T H H T T H H H T H Number of Heads: 6 Number of Tails: 5

 Challenge 04 - Five in a Row 

Lets see how many flips it takes me to flip 5 Tails ('T') in a row.

When your program runs, it might look like this:

H T H H T H T H T T T T T Number of flips: 13

 Challenge 05 - The Time Game 

Add the following functionality to your existing coin flip program:
Here is some source code to help you get started:

import random import timeit side_to_target = input("Target Heads or Tails? Enter 'H' or 'T': ") frequency_to_target = int(input("How many to target in a row: ")) target_reached = False total_flips = 0 #declare other variables here #main loop: timeStarted = timeit.default_timer() while not(target_reached): #...code to process flip total_flips += 1 print("Target reached in", total_flips, "flip(s).") elapsed = timeit.default_timer() - timeStarted print("Program took " + "{0:.2f}".format(round(elapsed,2)) + " seconds.")