Hack #1 - Class Notes

  • Simulations: abstractions that mimic more complex objects or phenomena from world
  • varying sets of values to simulate real life
  • simplification is necessary
  • variability and randomness is taken into account

Hack #2 - Functions Classwork

import random
otherclothes = ["white hat", "blue shirt", "purple socks"]
myclothes = ["red shoes", "green pants", "tie", "belt"]

def mycloset():
    my = myclothes[(random.randint(0,(len(myclothes) - 1)))]
    other = otherclothes[random.randint(0,(len(otherclothes) - 1))]
    i = input("do you want to trash or add clothes")
    print("closet before trashing/adding: " + str(myclothes))
    if i == "trash":
        myclothes.remove(my)
        print("closet after removing an item: " + str(myclothes))
    elif i == "add":
        myclothes.append(other)
        print("closet after adding an item: " + str(myclothes))
    else:
        print("not a valid input")

mycloset()

    
closet before trashing/adding: ['red shoes', 'green pants', 'tie', 'belt']
closet after adding an item: ['red shoes', 'green pants', 'tie', 'belt', 'purple socks']

Weighted Coin Flip

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: #assigning 0 to be heads--> if 0 is chosen then it will print, "Heads"
        return("Heads")
    else:
        return("Tails")
#Tossing the coin 5 times:
t1 = coinflip()
t2 = coinflip()
t3 = coinflip()
t4 = coinflip()
t5 = coinflip()

print(t1)
print(t2)
print(t3)
print(t4)
print(t5)
Tails
Tails
Tails
Heads
Heads

Hack #3 - Binary Simulation Problem

import random

dec = 0

def randomnum(): # function for generating random int
    ran = random.randint(1,255)
    return(ran)

def converttobin(n): # function for converting decimal to binary
    bin = ""
    i = 7

    while i >= 0:
        if n % (2**i) == n:
            bin = bin + "0"
            i -= 1
        else:
            bin = bin + "1"
            n -= 2**i
            i -= 1

    return(bin)


survivorstatus = ["hykeem", "kendrick", "don", "travis" , "ye", "jeffrey", "quavo", "offset"]

def survivors(binary): # function to assign position
    i = 0
    print("inital survivors: " + str(survivorstatus))
    while i < len(survivorstatus):
        if binary[i] == "0":
            rem = survivorstatus[i]
            survivorstatus.remove(rem)
            i += 1
        else:
            i += 1
    print("final survivors: " + str(survivorstatus))

ran1 = randomnum()
bin1 = converttobin(ran1)
survivors(bin1)
inital survivors: ['hykeem', 'kendrick', 'don', 'travis', 'ye', 'jeffrey', 'quavo', 'offset']
final survivors: ['kendrick', 'travis', 'ye', 'quavo']

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

a = roll()
b = roll()
c = roll()
d = roll()

print(a)
print(b)
print(c)
print(d)
3
3
5
4

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
questions = [
    
    ((3,0), "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.", 
    "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."),
    
    ((4,0), "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?",
    "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."),

    ((1,0), "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?", 
    "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"),

    ((2,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?", 
    "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."),

    ((1,0), "what string is used to define a function in python?", 
    "def", 
    "define", 
    "function",
    "string"),

    ((1,0), "what loop continues as long as a given condition is true?", 
    "while", 
    "for", 
    "if",
    "loop")
]

def questionloop(qlist):
    score = 0
    for sub in qlist:
        print("question: " + sub[1])
        print("answer 1: " + sub[2])
        print("answer 2: " + sub[3])
        print("answer 3: " + sub[4])
        print("answer 4: " + sub[5])
        res = input("Choose an answer number: ")
        if int(res) == sub[0][0]:
            score += 1
            continue
        elif int(res) == sub[0][1]:
            score += 1
        else:
            continue

    percent = score * 100 / 6
    passfail = ""

    if percent < 70:
        passfail = "failed"
    else:
        passfail = "passed"

    print("You " + str(passfail) + " the test with " + str(percent) + "%.")

questionloop(questions)
question: 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 1: The simulation is an abstraction and therefore cannot contain any bias
answer 2: The simulation may accidentally contain bias due to the exclusion of details.
answer 3: If the simulation is found to contain bias, then it is not possible to remove the bias from the simulation.
answer 4: The only way for the simulation to be biased is if the researcher intentionally used data that favored their desired output.
question: 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 1: No, it's not a simulation because it does not include a visualization of the results.
answer 2: No, it's not a simulation because it does not include all the details of his life history and the future financial environment.
answer 3: Yes, it's a simulation because it runs on a computer and includes both user input and computed output.
answer 4: Yes, it's a simulation because it is an abstraction of a real world scenario that enables the drawing of inferences.
question: 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 1: Realistic sound effects based on the material of the baseball bat and the velocity of the hit
answer 2: A depiction of an audience in the stands with lifelike behavior in response to hit accuracy
answer 3: Accurate accounting for the effects of wind conditions on the movement of the ball
answer 4: A baseball field that is textured to differentiate between the grass and the dirt
question: 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 1: The simulation will not contain any bias that favors one body type over another, while an experiment will be biased.
answer 2: The simulation can be run more safely than an actual experiment
answer 3: The simulation will accurately predict the parachute's safety level, while an experiment may be inaccurate due to faulty experimental design.
answer 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.
question: what string is used to define a function in python?
answer 1: def
answer 2: define
answer 3: function
answer 4: string
question: what loop continues as long as a given condition is true?
answer 1: while
answer 2: for
answer 3: if
answer 4: loop
You passed the test with 83.33333333333333%.

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

buy/sell stocks simulator

import random

value = 100
profit = 0
money = 100
r = 1

while profit > -80:
    print("round " + str(r))
    mul = random.randint(1,100) / 30
    value = round((mul * value),0)
    ans = input("sell, buy, or end?")
    if ans == "buy":
        profit += (value - money)
        money = value
        print("value = " + str(value))
        print("profit = " + str(profit))
        print("money = " + str(money))
        print("")
        r += 1
    elif ans == "end":
        print("game over")
        break
    else:
        print("value = " + str(value))
        print("profit = " + str(profit))
        print("money = " + str(money))
        print("")
        r += 1

print("game over")
round 1
value = 127.0
profit = 27.0
money = 127.0

round 2
value = 398.0
profit = 298.0
money = 398.0

round 3
value = 199.0
profit = 99.0
money = 199.0

round 4
game over
game over