Hack #1 - Class Notes

Write any extra notes you have here

Simulations - abstractions that mimic more complex realities, problems, or phenomena. ex: school daily routines...

  • necessary to remove specific details or simplify aspects
  • allow for formulation of hypothesis
  • varying set of values to reflect a changing state

Hack #2 - Functions Classwork

import random
def mycloset():
    clothes = ["Padres Hoodie" "Jeans" "Shoes" ]
    newbies = ["Yellowstone Merch" "Track Pants" "FlipFlops"]
    x = random.randint(2, myclothes)
    y = random.randint(2, newbies)

    return mycloset()

mycloset()
---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
/mnt/c/Users/rohan/vscode/RohanRepository/_notebooks/2022-12-16-GroupSixteen.ipynb Cell 4 in <cell line: 10>()
      <a href='vscode-notebook-cell://wsl%2Bubuntu/mnt/c/Users/rohan/vscode/RohanRepository/_notebooks/2022-12-16-GroupSixteen.ipynb#X21sdnNjb2RlLXJlbW90ZQ%3D%3D?line=5'>6</a>     y = random.randint(2, newbies)
      <a href='vscode-notebook-cell://wsl%2Bubuntu/mnt/c/Users/rohan/vscode/RohanRepository/_notebooks/2022-12-16-GroupSixteen.ipynb#X21sdnNjb2RlLXJlbW90ZQ%3D%3D?line=7'>8</a>     return mycloset()
---> <a href='vscode-notebook-cell://wsl%2Bubuntu/mnt/c/Users/rohan/vscode/RohanRepository/_notebooks/2022-12-16-GroupSixteen.ipynb#X21sdnNjb2RlLXJlbW90ZQ%3D%3D?line=9'>10</a> mycloset()

/mnt/c/Users/rohan/vscode/RohanRepository/_notebooks/2022-12-16-GroupSixteen.ipynb Cell 4 in mycloset()
      <a href='vscode-notebook-cell://wsl%2Bubuntu/mnt/c/Users/rohan/vscode/RohanRepository/_notebooks/2022-12-16-GroupSixteen.ipynb#X21sdnNjb2RlLXJlbW90ZQ%3D%3D?line=2'>3</a> clothes = ["Padres Hoodie" "Jeans" "Shoes" ]
      <a href='vscode-notebook-cell://wsl%2Bubuntu/mnt/c/Users/rohan/vscode/RohanRepository/_notebooks/2022-12-16-GroupSixteen.ipynb#X21sdnNjb2RlLXJlbW90ZQ%3D%3D?line=3'>4</a> newbies = ["Yellowstone Merch" "Track Pants" "FlipFlops"]
----> <a href='vscode-notebook-cell://wsl%2Bubuntu/mnt/c/Users/rohan/vscode/RohanRepository/_notebooks/2022-12-16-GroupSixteen.ipynb#X21sdnNjb2RlLXJlbW90ZQ%3D%3D?line=4'>5</a> x = random.randint(2, myclothes)
      <a href='vscode-notebook-cell://wsl%2Bubuntu/mnt/c/Users/rohan/vscode/RohanRepository/_notebooks/2022-12-16-GroupSixteen.ipynb#X21sdnNjb2RlLXJlbW90ZQ%3D%3D?line=5'>6</a> y = random.randint(2, newbies)
      <a href='vscode-notebook-cell://wsl%2Bubuntu/mnt/c/Users/rohan/vscode/RohanRepository/_notebooks/2022-12-16-GroupSixteen.ipynb#X21sdnNjb2RlLXJlbW90ZQ%3D%3D?line=7'>8</a> return mycloset()

NameError: name 'myclothes' is not defined
import random

def coinflip():         #def function 
    randomflip = random.randint(0, 2 ) 
    if randomflip == 0 or randomflip == 1: 
        print("Heads")
    else:
        if randomflip == 2: 
            print("Tails")

t1 = coinflip()
t2 = coinflip()
t3 = coinflip()
t4 = coinflip()
t5 = coinflip()
Heads
Heads
Heads
Heads
Tails
from random import choice

questions = [
    ("What is 3+2", "5"),
    ("What is 1+1?", "2"),
    ("what is 2+1", "3"),
]


def ask_question():
    question, answer = choice(questions)
    print(question)

    response = input()

    return response == answer

correct = 0

answer = ask_question()
Q1 = input()
if Q1 == answer:
    
answer = ask_question()
    Q2 = input()
        if Q2 == answer:
   
Q3 = input()
if Q3 == :
   

Q4 = input()


print( " you scored " + str(correct) +"/" + str(questions))
  Input In [6]
    answer = ask_question()
    ^
IndentationError: expected an indented block

Hack #3 - Binary Simulation Problem

import random

def randomnum(): # function for generating random int
    generator = random.randint(0, 255)
    return x

def converttobin(n): # function for converting decimal to binary
    --

def survivors(binary): # function to assign position
    survivorstatus = ["Jiya", "Shruthi", "Noor", "Ananya" , "Peter Parker", "Andrew Garfield", "Tom Holland", "Tobey Maguire"]
    for bin in binary:
        if bin = 0:
        print (survivorstatus[bin] "is a zombie")
        else:
            print (survivorstatus[num] "is a survivor")
    # replace the names above with your choice of people in the house

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():
    x = random.randint(1,6)
    return x

roll1 = diceroll()
roll2 = diceroll()
roll3 = diceroll()
roll4 = diceroll()
roll5 = diceroll()
roll6 = diceroll()
print("Roll 1:", roll1)
print("Roll 2:", roll2)
print("Roll 3:", roll3)
print("Roll 4:", roll4)
print("Roll 5:", roll5)
print("Roll 6:", roll6)
Roll 1: 2
Roll 2: 5
Roll 3: 1
Roll 4: 1
Roll 5: 4
Roll 6: 5

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
from random import choice

questions = [
    ("What is 3+2", "5"),
    ("What is 1+1?", "2"),
    ("what is 2+1", "3"),
]


def ask_question():
    question, answer = choice(questions)
    print(question)

    response = input()

    return response == answer

correct = 0

answer = ask_question()
Q1 = input()
if Q1 == answer:
    
answer = ask_question()
    Q2 = input()
        if Q2 == answer:
   
Q3 = input()
if Q3 == :
   

Q4 = input()


print( " you scored " + str(correct) +"/" + str(questions))

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...

cereals = ["Cheerios", "Frosted Flakes", "Cocoa Puffs", "Lucky Charms"] ## Which cereal am I going to eat for breakfast?

def pick_cereal(desired_cereal):
    if desired_cereal in cereals:
        return f"{desired_cereal} is a great choice!"
    else:
        return "Sorry, that cereal is not available."

print(pick_cereal("Cheerios"))  # Output: "Cheerios is a great choice!"
print(pick_cereal("Raisin Bran"))  # Output: "Sorry, that cereal is not available."