Question | Answer |
---|---|
Name(First+Last) | Kaylee Hou |
1 | raunak |
2 | raunak |
3 | C- To make the simulation more accurate |
4 | C- Imperfections on aircraft |
5 | C Situation considered |
6 | A- simulation, because it's too dangerous to have this be an experiment |
7 | A- simulation, we don't want to experiment with this because it could cause great harm on the environment |
8 | raunak |
9 | B- experiment/calculation because there is no need to simulate anything, this will only be a simple calculation of the average |
import random
print("Welcome to a coin flip simulation!")
print("----------------------------------")
n = 10000 #this value can easily be changed to change the sample size
heads = 0
tails = 0
for i in range(n):
flip = random.randint(1,2) # get a random number between 1 and 2
if flip == 1: # head
heads = heads + 1
else: # tail
tails = tails + 1
print('Number of heads:', heads)
print('Number of tails:', tails)
Here is a simulation of a coin toss, which accurately simulates how many heads or tails you get if you were to flip a coin 10,000 times. Using a simulation is much more efficient and better than actually running an experiment because it saves a lot of time and effort. It would take forever to flip a coin 10,000 times. I set n equal to the sample size and heads and tails to 0 which is the default value. Then using a for loop, with each flip, the procedure will either give heads or tails until the coin has been flipped 10000 times in the simulation.