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.

Hack #2 - Functions Classwork

import random
x = random.randint(1,100)
print(x)
57
def mycloset():
    myclothes = ["red shoes", "green pants", "tie", "belt"]
    import random
    x = random.choice(myclothes)
    return x
    myclothes.remove    
mycloset()
'green pants'

Weighted Coin Flip Program

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()
Tails
Heads
Tails
Heads
Heads

Hack #3 - Binary Simulation Problem

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))
Random decimal: 105
Random binary: 1101001
Zombies: ['Noor', 'Peter Parker', 'Andrew Garfield', 'Tobey Maguire']
Not Zombies: ['Jiya', 'Shruthi', 'Ananya', 'Tom Holland']

Hack #4 - Thinking through a problem

  • create your own simulation involving a dice roll
  • should include randomization and a function for rolling + multiple trials
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()
6
4
4
3
3

Hack 5 - Applying your knowledge to situation based problems

Using the questions bank below, create a quiz that presents the user a random question and calculates the user's score. You can use the template below or make your own. Making your own using a loop can give you extra points.

  1. 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:
      1. The simulation is an abstraction and therefore cannot contain any bias
      2. The simulation may accidentally contain bias due to the exclusion of details.
      3. If the simulation is found to contain bias, then it is not possible to remove the bias from the simulation.
      4. The only way for the simulation to be biased is if the researcher intentionally used data that favored their desired output.
  2. 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
      1. No, it's not a simulation because it does not include a visualization of the results.
      2. No, it's not a simulation because it does not include all the details of his life history and the future financial environment.
      3. Yes, it's a simulation because it runs on a computer and includes both user input and computed output.
      4. Yes, it's a simulation because it is an abstraction of a real world scenario that enables the drawing of inferences.
  3. 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
      1. Realistic sound effects based on the material of the baseball bat and the velocity of the hit
      2. A depiction of an audience in the stands with lifelike behavior in response to hit accuracy
      3. Accurate accounting for the effects of wind conditions on the movement of the ball
      4. A baseball field that is textured to differentiate between the grass and the dirt
  4. 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
      1. The simulation will not contain any bias that favors one body type over another, while an experiment will be biased.
      2. The simulation can be run more safely than an actual experiment
      3. The simulation will accurately predict the parachute's safety level, while an experiment may be inaccurate due to faulty experimental design.
      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.
    • this question has 2 correct answers
  5. YOUR OWN QUESTION; can be situational, pseudo code based, or vocab/concept based
  6. YOUR OWN QUESTION; can be situational, pseudo code based, or vocab/concept based

Quiz

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))
- - - - -Question 3 options- - - - -
1. Realistic sound effects based on the material of the baseball bat and the velocity of the hit
2. A depiction of an audience in the stands with lifelike behavior in response to hit accuracy
3. Accurate accounting for the effects of wind conditions on the movement of the ball
4. A baseball field that is textured to differentiate between the grass and the dirt
- - - - -Question 1 options- - - - -
1. The simulation is an abstraction and therefore cannot contain any bias
2. The simulation may accidentally contain bias due to the exclusion of details.
3. If the simulation is found to contain bias, then it is not possible to remove the bias from the simulation.
4. The only way for the simulation to be biased is if the researcher intentionally used data that favored their desired output.
- - - - -Question 5 options- - - - -
1. Equations
2. Dice Roll
3. Spinners
4. Coin Flip
- - - - -Question 2 options- - - - -
1. No, it's not a simulation because it does not include a visualization of the results.
2. No, it's not a simulation because it does not include all the details of his life history and the future financial environment.
3. Yes, it's a simulation because it runs on a computer and includes both user input and computed output.
4. Yes, it's a simulation because it is an abstraction of a real world scenario that enables the drawing of inferences.
- - - - -Question 6 options- - - - -
1. Yes, all computer simulations contain bias
2. Yes, some computer simulations contain bias
3. No, computer simulations contain no bias
4. No, computer simulations contains objects that it is not capable of having bias towards
- - - - -Question 4 options- - - - -
1. The simulation will not contain any bias that favors one body type over another, while an experiment will be biased.
2. The simulation can be run more safely than an actual experiment
3. The simulation will accurately predict the parachute's safety level, while an experiment may be inaccurate due to faulty experimental design.
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.
 You scored 6/6

Hack #6 / Challenge - Taking real life problems and implementing them into code

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")
Woke up Monday at 7:32am
Woke up Tuesday at 7:21am
Woke up Wednesday at 7:31am
Woke up Thursday at 7:11am
Woke up Friday at 7:10am