Unit 3 Lesson 16, Student Copy
- 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 mimic the real world, things we cannot do in real life
- Reflect the changing state of a phenomenon
- Its impossible to factor everything into a simulation(the results may be a bit skewed)
- The importance of simulaitons is to have test cases
- Account for the importance of the simulations ideas
- Random gives random
import random
#The below 2 inputs get the maximum and the minimum
min = int(input("WHat is lowest num"))
max = int(input("HIghest num plz"))
#Sets x to a random value in between the min and maximum
x = random.randint(min,max)
print(x)
import random
#The two user inputs ask what items the user wants to change from the myclothes list
add = input("What do you want to add")
remove = input("What you to remove")
def mycloset():
#List of clothes in the closet
myclothes = ["red shoes", "green pants", "tie", "belt"]
#The below lines add or remove the item from the users closet
myclothes.append(add)
myclothes.remove(remove)
#Prints a random clothing item from the list
print(random.choice(myclothes))
mycloset()
import random
def coinflip(): #def function
randomflip = random.randint(1,3) #picks either 0 or 1 randomly (50/50 chance of either)
if randomflip == 2 or randomflip ==1 : #assigning 0 to be heads--> if 0 is chosen then it will print, "Heads"
print("Heads")
else:
if randomflip == 3: #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 randomnum(): # function for generating random int
integer = random.randint(0,255)
return integer
def converttobin(n): # function for converting decimal to binary
binary = str(bin(n)[2:].zfill(8))
def survivors(binary): # function to assign position
survivorstatus = ["Jalen", "AJ", "Miles", "Sanders" , "Jordan", "Lane", "Jason", "Darius"]
i = 0
for bit in binary:
if bit == "0":
print(survivorstatus[i], "is a zombie")
if bit == "1":
print(print(survivorstatus[i], "is a safe"))
survivors(converttobin(randomnum()))
# replace the names above with your choice of people in the house
import random
#Asks for user input about how many dice rolls they want
n = int(input("How many dice rolls?"))
#Function roll
def roll(n):
#Cycles through how many rolls they want
for i in range (n):
#Rolls the dice (getting a random number between 1 and 6)
x = random.randint(1,6)
#prints the roll of the dice
print("Your dice roll is", x)
roll(n)
- 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
def quiz():
# Create a list of questions
questions = [
"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.",
"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?",
"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?",
"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?",
"What is the use of simulations?",
"What are problems we encounter with simulations"
]
# Create a list of answers
answers = [
"The simulation may accidentally contain bias due to the exclusion of details",
"Yes, it's a simulation because it is an abstraction of a real world scenario that enables the drawing of inferences.",
"Thomas Edison",
"H",
"Mount Everest",
""
]
# Create a list of multiple choice options for each question
options = [
["Paris", "London", "Rome", "Madrid"],
["Saturn", "Jupiter", "Mars", "Venus"],
["Thomas Edison", "Benjamin Franklin", "Nikola Tesla", "Alessandro Volta"],
["H", "He", "Li", "Be"],
["Mount Everest", "K2", "Kangchenjunga", "Lhotse"],
]
# Randomly select a question
question = random.choice(questions)
print(question)
# Get the index of the selected question
index = questions.index(question)
# Get the correct answer for the selected question
answer = answers[index]
# Get the multiple choice options for the selected question
choices = options[index]
# Print the multiple choice options
for i, option in enumerate(choices):
print(str(i+1) + ". " + option)
# Get the user's response to the question
response = input("Your answer: ")
# Check if the user's response is correct
if response.lower() == answer.lower():
print("Correct!")
else:
print("Incorrect. The correct answer is: " + answer)
quiz()
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...
my code simulates who will win an nfl game played 10 times.
import random
teams = ["eagles", "cowboys"]
def game():
eagles = 0
cowboys = 0
for i in range (10):
winner = random.choice(teams)
if winner == "eagles":
eagles +=1
if winner == "cowboys":
cowboys +=1
print("Eagles won",eagles,"times", "Cowboys won",cowboys,"times")
game()