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
import random
my_clothes = []
possible_clothes = ["Red shirt", "Orange shirt", "Yellow shirt", "Green shirt", "Blue shirt", "Purple shirt", "Red Pants", "Yellow Pants", "Blue Pants", "Orange Scarf", "Green Scarf", "Purple Scarf"]
cont = "y"
def clothes():
user_input = input("Do you want to add or remove clothes from your closet?")
if user_input.lower() == "add":
choice = random.choice(possible_clothes)
my_clothes.append(choice)
elif user_input.lower() == "remove":
choice = random.choice(my_clothes)
my_clothes.remove(choice)
while cont.lower() == "y":
clothes()
print(my_clothes)
cont = input("Do you want to continue? [Y/N]")
cont = cont.lower()
import random
def randomnum(): # function for generating random int
number = random.randint(128,255)
return number
def converttobin(n): # function for converting decimal to binary
binary = bin(n)
binary = binary[2:]
binary = list(binary)
return binary
def survivors(binary): # function to assign position
survivors = ["Jiya", "Shruthi", "Noor", "Ananya" , "Peter Parker", "Andrew Garfield", "Tom Holland", "Tobey Maguire"]
status = []
for person in survivors:
died = random.choice(binary)
status.append(died)
if died == '1':
print(f"{person} has survived!")
if died == '0':
print(f"{person} has died.")
# replace the names above with your choice of people in the house
number = randomnum()
binary = converttobin(number)
survivors(binary)
import random
def roll(times):
print(f"Rolling the dice {times} times... ")
one = 0
two = 0
three = 0
four = 0
five = 0
six = 0
i=0
while i <= times:
result = random.randint(1,6)
if result == 1:
one += 1
elif result == 2:
two += 1
elif result == 3:
three += 1
elif result == 4:
four += 1
elif result == 5:
five += 1
elif result == 6:
six += 1
print(f"Rolling the dice... {result}!")
i+=1
return one, two, three, four, five, six
times = input("How many times do you want to roll the dice?")
one, two, three, four, five, six = roll(int(times))
total = one+two+three+four+five+six
print(f"""
Occurrences:
1: {one} ({round(((one/total)*100), 2)}%)
2: {two} ({round(((two/total)*100), 2)}%)
3: {three} ({round(((three/total)*100), 2)}%)
4: {four} ({round(((four/total)*100), 2)}%)
5: {five} ({round(((five/total)*100), 2)}%)
6: {six} ({round(((six/total)*100), 2)}%)
""")
- 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
- Simulations are _
- answer options
- abstractions that mimic real world occurrences
- abstractions that are results from real world occurrences
- abstractions that cannot be replicated
- fun
- answer options
- What module can you use to simulate random events?
- answer options
- Os
- Time
- Math
- Random
- answer options
questions = 6
correct = 0
Q1 = input()
if Q1 == "2":
print("Correct!")
correct += 1
Q2 = input()
if Q2 == "2":
print("Correct!")
correct += 1
Q3 = input()
if Q3 == "3":
print("Correct!")
correct += 1
Q4 = input()
if Q4 == "2":
print("Correct!")
correct += 1
Q5 = input()
if Q5 == "1":
print("Correct!")
correct += 1
Q6 = input()
if Q6 == "4":
print("Correct!")
correct += 1
print( " you scored " + str(correct) +"/" + str(questions))
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...
def position(angle, strength, time):
strength = 1/strength
pos = -(strength)*(time**2)+(angle*time)
return pos
def velocity(angle, strength, time):
strength = 1/strength
velo = -(2*strength)*(time)+(angle)
return velo
def acceleration(strength):
strength = 1/strength
accel = -(2*strength)
return accel
angle = input("What angle do you want to throw the ball at?")
angle = int(angle)
strength = input("How hard do you want to throw the ball?")
strength = int(strength)
time = 0
while True:
pos = position(angle,strength,time)
velo = velocity(angle,strength,time)
accel = acceleration(strength)
print(f"The ball at {time} seconds is {pos} feet off the ground, moving at {velo} feet per second, and accelerating at {accel} feet per second, per second")
if pos == 0:
if time == 0:
time += 1
elif time != 0:
break
else:
time += 1