Hack #1 - Class Notes

Write any extra notes you have here

Hack #2 - Functions Classwork

import random

myclothes = ['Black Shoes','Jeans','Grey Shorts','Tan Shorts','Black T-Shirt']
def throwout():
    y = len(myclothes)-1
    x = random.randint(0,y)
    myclothes.remove(myclothes[x])
print(myclothes)
throwout()
print(myclothes)
['Black Shoes', 'Jeans', 'Grey Shorts', 'Tan Shorts', 'Black T-Shirt']
['Black Shoes', 'Grey Shorts', 'Tan Shorts', 'Black T-Shirt']

Hack #3 - Binary Simulation Problem

import random
survivorstatus = ["William Hartnell", "Partic Troughton", "John Pertwee", "Tom Baker" , "Peter Davison", "Colin Baker", "Sylvester McCoy", "Paul McGann"]

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

def converttobin(n): # function for converting decimal to binary
    thelist = []
    while n > 0:
        if n % 2 == 0:
            thelist.append(0)
            n = n / 2
        else:
            thelist.append(1)
            n = n / 2
            n = n - 0.5
    while len(thelist) < 8:
        thelist.append(0)
    return thelist

def survivors(binary,survivors): # function to assign position
    survivorlist = []
    for i in range(len(binary)):
        if binary[i] == 0:
            survivorlist.append(survivors[i])
        else:
            print('dead')
    return survivorlist
            

assignments = converttobin(randomnum())
remaining = survivors(assignments,survivorstatus)
print('Remaining Survivors:',remaining)
    # replace the names above with your choice of people in the house
dead
dead
dead
Remaining Survivors: ['William Hartnell', 'Partic Troughton', 'Peter Davison', 'Colin Baker', 'Paul McGann']

Hack #4 - Thinking through a problem

  • create your own simulation involving a dice roll
  • should include randomization and a function for rolling + multiple trials
from random import randint

def rolldice():
    sides = int(input('dice side count:'))
    rolls = int(input('number of rolls:'))
    out = []
    for i in range(rolls):
        x = randint(0,sides)
        out.append(x)
    return(out)

print(rolldice())
[0, 6, 0, 7]

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
correct = 0
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.":["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."],
    "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."],
    "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"],
    "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."]
}

def answers(question):
    used = []
    for i in range(len(questions[question])):
        option = random.randint(0,3)
        while option in used == True:
            option = random.randint(0,3)
        used.append(option)
        print(questions[question][option])

#Q1
Q1 = "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."
print(Q1)
answers(Q1)
solution = input('Please type the answer here, keep in mind the exact capitalization and punctuation as shown.')
if solution == "If the simulation is found to contain bias, then it is not possible to remove the bias from the simulation.":
    correct = correct + 1

Q2 = "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?"
print(Q2)
answers(Q2)
solution = input('Please type the answer here, keep in mind the exact capitalization and punctuation as shown.')
if solution == "Yes, it's a simulation because it runs on a computer and includes both user input and computed output.":
    correct = correct + 1

Q3 = "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?"
print(Q3)
answers(Q3)
solution = input('Please type the answer here, keep in mind the exact capitalization and punctuation as shown.')
if solution == "Accurate accounting for the effects of wind conditions on the movement of the ball":
    correct = correct + 1

Q4 = "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?"
print(Q4)
answers(Q4)
solution = input('Please type the answer here, keep in mind the exact capitalization and punctuation as shown.')
if solution == "The simulation can be run more safely than an actual experiment":
    correct = correct + 1
elif solution == "The simulation can test the parachute design in a wide range of environmental conditions that may be difficult to reliably reproduce in an experiment.":
    correct = correct + 1
print( " you scored " + str(correct) +"/" + str(len(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.
The simulation may accidentally contain bias due to the exclusion of details.
The simulation is an abstraction and therefore cannot contain any bias
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.
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 all the details of his life history and the future financial environment.
No, it's not a simulation because it does not include all the details of his life history and the future financial environment.
No, it's not a simulation because it does not include a visualization of the results.
Yes, it's a simulation because it runs on a computer and includes both user input and computed output.
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?
A baseball field that is textured to differentiate between the grass and the dirt
Accurate accounting for the effects of wind conditions on the movement of the ball
A depiction of an audience in the stands with lifelike behavior in response to hit accuracy
A depiction of an audience in the stands with lifelike behavior in response to hit accuracy
---------------------------------------------------------------------------
KeyboardInterrupt                         Traceback (most recent call last)
/home/colinmills/vscode/ColinMills/_notebooks/2022-12-12-hw.ipynb Cell 11 in <cell line: 36>()
     <a href='vscode-notebook-cell://wsl%2Bubuntu/home/colinmills/vscode/ColinMills/_notebooks/2022-12-12-hw.ipynb#X12sdnNjb2RlLXJlbW90ZQ%3D%3D?line=33'>34</a> print(Q3)
     <a href='vscode-notebook-cell://wsl%2Bubuntu/home/colinmills/vscode/ColinMills/_notebooks/2022-12-12-hw.ipynb#X12sdnNjb2RlLXJlbW90ZQ%3D%3D?line=34'>35</a> answers(Q3)
---> <a href='vscode-notebook-cell://wsl%2Bubuntu/home/colinmills/vscode/ColinMills/_notebooks/2022-12-12-hw.ipynb#X12sdnNjb2RlLXJlbW90ZQ%3D%3D?line=35'>36</a> solution = input('Please type the answer here, keep in mind the exact capitalization and punctuation as shown.')
     <a href='vscode-notebook-cell://wsl%2Bubuntu/home/colinmills/vscode/ColinMills/_notebooks/2022-12-12-hw.ipynb#X12sdnNjb2RlLXJlbW90ZQ%3D%3D?line=36'>37</a> if solution == "Accurate accounting for the effects of wind conditions on the movement of the ball":
     <a href='vscode-notebook-cell://wsl%2Bubuntu/home/colinmills/vscode/ColinMills/_notebooks/2022-12-12-hw.ipynb#X12sdnNjb2RlLXJlbW90ZQ%3D%3D?line=37'>38</a>     correct = correct + 1

File ~/.local/lib/python3.8/site-packages/ipykernel/kernelbase.py:1177, in Kernel.raw_input(self, prompt)
   1173 if not self._allow_stdin:
   1174     raise StdinNotImplementedError(
   1175         "raw_input was called, but this frontend does not support input requests."
   1176     )
-> 1177 return self._input_request(
   1178     str(prompt),
   1179     self._parent_ident["shell"],
   1180     self.get_parent("shell"),
   1181     password=False,
   1182 )

File ~/.local/lib/python3.8/site-packages/ipykernel/kernelbase.py:1219, in Kernel._input_request(self, prompt, ident, parent, password)
   1216             break
   1217 except KeyboardInterrupt:
   1218     # re-raise KeyboardInterrupt, to truncate traceback
-> 1219     raise KeyboardInterrupt("Interrupted by user") from None
   1220 except Exception:
   1221     self.log.warning("Invalid Message:", exc_info=True)

KeyboardInterrupt: Interrupted by user

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