divider

Objective

Your task is to create a program that simulates flipping a coin multiple times based on user input. The program will keep track of how many times heads and tails occur and display the counts and percentages at the end.

Skills to Practice

  • icon Using loops to repeat actions based on user input
  • icon Generating random numbers
  • icon Calculating statistics
divider

Tasks

  • icon Create a new project named application-2-6
  • icon Complete the following tasks:
    • icon Prompt the user to enter the number of times they want to flip the coin.
    • icon Use a loop to "flip" the coin the specified number of times.
    • icon Keep track of the number of heads and tails.
    • icon Calculate the percentage of heads and tails.
    • icon Display the total number of heads and tails and their respective percentages.
divider

Sample Output

Sample Output
Enter the number of times to flip the coin: 10 [Enter]
Flip 1: Heads
Flip 2: Tails
Flip 3: Heads
Flip 4: Heads
Flip 5: Tails
Flip 6: Heads
Flip 7: Tails
Flip 8: Tails
Flip 9: Heads
Flip 10: Heads
Results:
Heads: 6 (60%)
Tails: 4 (40%)

Begin Challenge