Python Math: Flip a coin 1000 times and count heads and tails
53.Coin Flip Simulator
Write a Python program to flip a coin 1000 times and count heads and tails.
Sample Solution:
Python Code:
import randomimport itertoolsresults = { 'heads': 0, 'tails': 0,}sides = list(results.keys())for i in range(10000): results[random.choice(sides)] += 1print('Heads:', results['heads'])print('Tails:', results['tails'])Sample Output:
Heads: 5037 Tails: 4963
Pictorial Presentation:
Flowchart:

For more Practice: Solve these Related Problems:
- Write a Python program to simulate flipping a coin 1000 times using random.choice() and then print the counts of heads and tails.
- Write a Python function to simulate coin tosses 1000 times, returning a dictionary with keys 'Heads' and 'Tails' and their respective counts.
- Write a Python script to simulate 1000 coin flips and calculate the percentage of heads and tails, printing a formatted report.
- Write a Python program to simulate coin tosses until one outcome reaches 600 occurrences and print the final counts.
Go to:
Previous: Write a Python program to shuffle the following elements randomly.
Next: Write a Python program to print a random sample of words from the system dictionary.
Python Code Editor:
Have another way to solve this solution? Contribute your code (and comments) through Disqus.
What is the difficulty level of this exercise?
Test your Programming skills with w3resource'squiz.
