Unit 3 Lesson 16 Notes, Hacks, and Homework
- 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
- Simulations are abstractions that mimic something more complex or events from the real world.
- Simulations are used to make an inference without contraints of the real world.
- Simulations use varying sets of values to reflect changes. They can also run randomness.
- When running a simulation, it is necessary to remove some details or aspects.
- Simulation Examples include. . .(Randomness)
- Dice rolling
- spinners
- molecular models
- chemical reactions
- Simulations can have bias towards one outcome due to not being able to take all of the variables into its control.
- With random, the result of the simulation will most likely not be the same.
import random
x = random.randint(1,100)
print(x)
def mycloset():
myclothes = ["red shoes", "green pants", "tie", "belt"]
import random
x = random.choice(myclothes)
return x
myclothes.remove
mycloset()
import random
def coinflip(): #def function
randomflip = random.randint(0, 2) #picks either 0 or 1 randomly (50/50 chance of either)
if randomflip >= 1: #assigning 0 to be heads--> if 0 is chosen then it will print, "Heads"
print("Heads")
else:
print("Tails")
#Tossing the coin 5 times:
t1 = coinflip()
t2 = coinflip()
t3 = coinflip()
t4 = coinflip()
t5 = coinflip()
import random
def randomnum(): # function for generating random int
x = random.randint(0, 255)
return x
def converttobin(n): # function for converting decimal to binary
y = bin(n)
y = y[2:]
return y
def survivors(binary): # function to assign position
survivorstatus = ["Jiya", "Shruthi", "Noor", "Ananya" , "Peter Parker", "Andrew Garfield", "Tom Holland", "Tobey Maguire"]
# replace the names above with your choice of people in the house
zombie = []
survivor = []
n = 0
for i in binary:
if binary[n] == "0":
zombie.append(survivorstatus[n])
else:
survivor.append(survivorstatus[n])
n += 1
while n < 8:
zombie.append(survivorstatus[n])
n += 1
return zombie, survivor
rnd = randomnum()
print("Random decimal: " + str(rnd))
c = converttobin(rnd)
print("Random binary: " + c)
(z, s) = survivors(c)
print("Zombies: " + str(z))
print("Not Zombies: " + str(s))
import random
def diceroll(): # function for generating random int
x = random.randint(1, 6)
print(x)
return x
d1 = diceroll()
d2 = diceroll()
d3 = diceroll()
d4 = diceroll()
d5 = diceroll()
- 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
import random
questions = 6
correct = 0
numquestions = [1, 2, 3, 4, 5, 6]
random.shuffle(numquestions)
for i in numquestions:
if i == 1:
print("- - - - -Question 1 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.")
Q1 = input("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.")
if Q1 == "2":
correct += 1
elif i == 2:
print("- - - - -Question 2 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.")
Q2 = input("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?")
if Q2 == "4":
correct += 1
elif i == 3:
print("- - - - -Question 3 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")
Q3 = input("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?")
if Q3 == "3":
correct += 1
elif i == 4:
print("- - - - -Question 4 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. The simulation can test the parachute design in a wide range of environmental conditions that may be difficult to reliably reproduce in an experiment.")
Q4 = input("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?")
if Q4 == "2":
correct += 1
if Q4 == "3":
correct += 1
elif i == 5:
print("- - - - -Question 5 options- - - - -")
print("1. Equations")
print("2. Dice Roll")
print("3. Spinners")
print("4. Coin Flip")
Q5 = input("Which option is NOT an example of a simulation using random as its main function for the output?")
if Q5 == "1":
correct += 1
else:
print("- - - - -Question 6 options- - - - -")
print("1. Yes, all computer simulations contain bias")
print("2. Yes, some computer simulations contain bias")
print("3. No, computer simulations contain no bias")
print("4. No, computer simulations contains objects that it is not capable of having bias towards")
Q6 = input("Do computer simulations contain bias?")
if Q6 == "2":
correct += 1
print( " You scored " + str(correct) +"/" + str(questions))
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...
import random
print("Woke up Monday at 7:" + str(random.randint(0, 3)) + str(random.randint(0, 9)) + "am")
print("Woke up Tuesday at 7:" + str(random.randint(0, 3)) + str(random.randint(0, 9)) + "am")
print("Woke up Wednesday at 7:" + str(random.randint(0, 3)) + str(random.randint(0, 9)) + "am")
print("Woke up Thursday at 7:" + str(random.randint(0, 3)) + str(random.randint(0, 9)) + "am")
print("Woke up Friday at 7:" + str(random.randint(0, 3)) + str(random.randint(0, 9)) + "am")