Unit 3.16 Simulations Notes
- Hack #1 - Class Notes
- Hack #2 - Functions Classwork
- Hack #3 - Binary Simulation Problem
- Hack #4 - Thinking through a problem
- Hack 5 - Applying your knowledge to situation based problems
- Hack #6 / Challenge - Taking real life problems and implementing them into code
Hack #1 - Class Notes
Write any extra notes you have here
- Simulations are abstractions that mimic more complex objects or phenomena from the real world
- Simple terms: computers are used to help calculate and analyze real world situations
- Simulations often end up being bias based on which details or real-world elements were included/excluded by the creator
- Variability and outliers in the world are stimulated in code using RNGs such as dice rolls, coin flips, etc.
- Stimulating situations allow us to predict results without real life consequences
Activity: Change the code below so that instead of using a fair coin, a weighted coin is flipped. THis means there is no longer an equal chance that either heads of tails will be flipped. Let's say there is a 2/3 chance of heads and only 1/3 chance of tails.
Hint: maybe you can increase the range of integers?
import random
def coinflip(): #def function
randomflip = random.randint(0, 2) #picks either 0 or 1 randomly (50/50 chance of either)
if randomflip == 0 or randomflip == 1: #assigning 0 to be heads--> if 0 is chosen then it will print, "Heads"
print("Heads")
else:
if randomflip == 2: #assigning 1 to be tails--> if 1 is chosen then it will print, "Tails"
print("Tails")
#Tossing the coin 5 times:
t1 = coinflip()
t2 = coinflip()
t3 = coinflip()
t4 = coinflip()
t5 = coinflip()
import random
def deadoralive(rng):
people = ["Person 0", "Person 1", "Person 2", "Person 3"]
# Generate a random number between 0 and 3 using the RNG from random package
num = rng.randint(0, 3)
# Convert the number to a binary string
binary = converttobin(num)
# Assign "dead" or "alive" status to each person based on the binary digits
for i in range(len(people)):
if binary[i] == "0": # Even number (ends in 0 in binary) = survived
people[i] = "Person " + str(i) + ":" + " survived"
else:
people[i] = "Person " + str(i) + ":" + " became a zombie"
return people
people = deadoralive(rng)
print(people)
import random
for i in range(3):
roll = random.randint(1,6)
print("On roll " + str(i + 1) + " you rolled: " + str(roll))
- A researcher gathers data about the effect of Advanced Placement®︎ classes on students' success in college and career, and develops a simulation to show how a sequence of AP classes affect a hypothetical student's pathway.Several school administrators are concerned that the simulation contains bias favoring high-income students, however.
- answer options:
- The simulation is an abstraction and therefore cannot contain any bias
- The simulation may accidentally contain bias due to the exclusion of details.
- If the simulation is found to contain bias, then it is not possible to remove the bias from the simulation.
- The only way for the simulation to be biased is if the researcher intentionally used data that favored their desired output.
- answer options:
- Jack is trying to plan his financial future using an online tool. The tool starts off by asking him to input details about his current finances and career. It then lets him choose different future scenarios, such as having children. For each scenario chosen, the tool does some calculations and outputs his projected savings at the ages of 35, 45, and 55.Would that be considered a simulation and why?
- answer options
- No, it's not a simulation because it does not include a visualization of the results.
- No, it's not a simulation because it does not include all the details of his life history and the future financial environment.
- Yes, it's a simulation because it runs on a computer and includes both user input and computed output.
- Yes, it's a simulation because it is an abstraction of a real world scenario that enables the drawing of inferences.
- answer options
- Sylvia is an industrial engineer working for a sporting goods company. She is developing a baseball bat that can hit balls with higher accuracy and asks their software engineering team to develop a simulation to verify the design.Which of the following details is most important to include in this simulation?
- answer options
- Realistic sound effects based on the material of the baseball bat and the velocity of the hit
- A depiction of an audience in the stands with lifelike behavior in response to hit accuracy
- Accurate accounting for the effects of wind conditions on the movement of the ball
- A baseball field that is textured to differentiate between the grass and the dirt
- answer options
- Ashlynn is an industrial engineer who is trying to design a safer parachute. She creates a computer simulation of the parachute opening at different heights and in different environmental conditions.What are advantages of running the simulation versus an actual experiment?
- answer options
- The simulation will not contain any bias that favors one body type over another, while an experiment will be biased.
- The simulation can be run more safely than an actual experiment
- The simulation will accurately predict the parachute's safety level, while an experiment may be inaccurate due to faulty experimental design.
- The simulation can test the parachute design in a wide range of environmental conditions that may be difficult to reliably reproduce in an experiment.
- this question has 2 correct answers
- answer options
- YOUR OWN QUESTION; can be situational, pseudo code based, or vocab/concept based
- YOUR OWN QUESTION; can be situational, pseudo code based, or vocab/concept based
print("Question 1:")
print("A researcher gathers data about the effect of Advanced Placement®︎ classes on students' success in college and career, and develops a simulation to show how a sequence of AP classes affect a hypothetical student's pathway.Several school administrators are concerned that the simulation contains bias favoring high-income students, however.")
print(" Answer options:")
print(" 1) The simulation is an abstraction and therefore cannot contain any bias")
print(" 2) The simulation may accidentally contain bias due to the exclusion of details.")
print(" 3) If the simulation is found to contain bias, then it is not possible to remove the bias from the simulation.")
print(" 4) The only way for the simulation to be biased is if the researcher intentionally used data that favored their desired output.")
answer = input("Enter the number of your answer choice: ")
if answer == "2":
print("Correct! The answer was 2")
else:
print("Incorrect. The correct answer was 2")
print(" ")
print("Question 2:")
print("Jack is trying to plan his financial future using an online tool. The tool starts off by asking him to input details about his current finances and career. It then lets him choose different future scenarios, such as having children. For each scenario chosen, the tool does some calculations and outputs his projected savings at the ages of 35, 45, and 55. Would that be considered a simulation and why?")
print(" Answer options:")
print(" 1) No, it's not a simulation because it does not include a visualization of the results.")
print(" 2) No, it's not a simulation because it does not include all the details of his life history and the future financial environment.")
print(" 3) Yes, it's a simulation because it runs on a computer and includes both user input and computed output.")
print(" 4) Yes, it's a simulation because it is an abstraction of a real world scenario that enables the drawing of inferences.")
answer1 = input("Enter the number of your answer choice: ")
if answer1 == "4":
print("Correct! The answer was 4")
else:
print("Incorrect. The correct answer was 4")
print(" ")
print("Question 3:")
print("Sylvia is an industrial engineer working for a sporting goods company. She is developing a baseball bat that can hit balls with higher accuracy and asks their software engineering team to develop a simulation to verify the design.Which of the following details is most important to include in this simulation?")
print(" Answer options:")
print(" 1) Realistic sound effects based on the material of the baseball bat and the velocity of the hit")
print(" 2) A depiction of an audience in the stands with lifelike behavior in response to hit accuracy")
print(" 3) Accurate accounting for the effects of wind conditions on the movement of the ball")
print(" 4) A baseball field that is textured to differentiate between the grass and the dirt")
answer3 = input("Enter the number of your answer choice: ")
if answer3 == "3":
print("Correct! The answer was 3")
else:
print("Incorrect. The correct answer was 3")
print(" ")
print("Question 4:")
print("Ashlynn is an industrial engineer who is trying to design a safer parachute. She creates a computer simulation of the parachute opening at different heights and in different environmental conditions.What are advantages of running the simulation versus an actual experiment (2 correct answers)?")
print(" Answer options:")
print(" 1) The simulation will not contain any bias that favors one body type over another, while an experiment will be biased.")
print(" 2) The simulation can be run more safely than an actual experiment")
print(" 3) The simulation will accurately predict the parachute's safety level, while an experiment may be inaccurate due to faulty experimental design.")
print(" 4) he simulation can test the parachute design in a wide range of environmental conditions that may be difficult to reliably reproduce in an experiment.")
answer4 = input("Enter the first number of your answer choice in order: ")
answer41 = input("Enter the second number of your answer choice in order: ")
if answer4 == "2":
print("Correct! The first answer was 2")
else:
print("Incorrect. The correct first answer was 2")
if answer41 == "4":
print("Correct! The second answer was 4")
else:
print("Incorrect. The correct second answer was 4")
print(" ")
print("Question 5: What variables would you least likely need to calculate the expected landing place of a football?")
print("")
print(" Answer options:")
print(" 1) Strength of quarterback")
print(" 2) Wind")
print(" 3) Smell of the football")
print(" 4) Weight of football")
answer5 = input("Enter the number of your answer choice: ")
if answer5 == "3":
print("Correct! The answer was 3")
else:
print("Incorrect. The correct answer was 3")
print(" ")
print("Question 6: To predict the hours of sleep someone may get in a night, the variable least likely to be factored into the prediction would be:")
print("")
print(" Answer options:")
print(" 1) Muscle strength")
print(" 2) Hours of sleep from previous night/day")
print(" 3) Sugar consumption within an hour before sleep")
print(" 4) Average hours of sleep per day in the past year")
answer6 = input("Enter the number of your answer choice: ")
if answer6 == "1":
print("Correct! The answer was 1")
else:
print("Incorrect. The correct answer was 1")
Create your own simulation based on your experiences/knowledge! Be creative! Think about instances in your own life, science, puzzles that can be made into simulations
Some ideas to get your brain running: A simulation that breeds two plants and tells you phenotypes of offspring, an adventure simulation...
France vs Argentina win probabilities (1:1 odds) and who scored the winning goal:
import random
# who wins the match
def winninggoalA():
randomscorer = random.randint(0, 3)
if randomscorer == 0:
print("Messi scored the game winner")
else:
if randomscorer == 1:
print("Fernandez scored the game winner")
else:
if randomscorer == 2:
print("Alvarez scored the game winner")
else:
if randomscorer == 3:
print("Di Maria scored the game winner")
def winninggoalF():
randomscorer2 = random.randint(0, 3)
if randomscorer2 == 0:
print("Mbappe scored the game winner")
else:
if randomscorer2 == 1:
print("Giroud scored the game winner")
else:
if randomscorer2 == 2:
print("Hernandez scored the game winner")
else:
if randomscorer2 == 3:
print("Griezmann scored the game winner")
def probability():
randomodds = random.randint(0, 1)
if randomodds == 0:
print("Argentina wins")
winninggoalA()
else:
print("France wins")
winninggoalF()
probability()
probability()
probability()