Unit 3.16 Hacks
Hack 1
Idea for a simulation: a platformer game that uses real physics to account for the movement of the character. Uses arrow keys for control and implements friction, gravity, and restitution forces/constants. An advantage of this simulation is that it lets us model real-life physical interactions with precision. I think a computer-generated simulation would be better in this case because it can be used for much more complex models/masses and tested multiple times.
questions_number = 6
answers_correct = 0
questions = [
"True or False: Simulations will always have the same result. \n A: True, \n B: False",
"True or False: A simulation has results that are more accurate than an experiment \n A: True, \n B: False",
"True or False: A simulation can model real world events that are not practical for experiments \n A: True, \n B: False",
"Which one of these is FALSE regarding simulations \n A: Reduces Costs, \n B: Is safer than real life experiments, \n C: More Efficient, \n D: More accurate than real life experiments",
"Which of the following scenarios would be the LEAST beneficial to have as a simulation \n A: A retail company wants to identify the item which sold the most on their website, \n B: A restaurant wants to determine if the use of robots will increase efficiency, \n C: An insurance company wants to study the impact of rain on car accidents, \n D: A sports car company wants to study design changes to their new bike design ",
"Which of the following is better to do as a simulation than as a calculation \n A: Keeping score at a basketball game, \n B: Keeping track of how many games a person has won, \n C: Determining the average grade for a group of tests, \n D: Studying the impact of carbon emissions on the environment"
]
question_answers = [
"B",
"B",
"A",
"D",
"A",
"D"
]
print("Welcome to the Simulations Quiz!")
def ask_question (question, answer):
print("\n", question)
user_answer = input(question)
print("You said: ", user_answer)
if user_answer == answer:
print("Correct!")
global answers_correct
answers_correct = answers_correct + 1
else:
print("You are incorrect")
for num in range(questions_number):
ask_question(questions[num], question_answers[num])
print("You scored: ", answers_correct, "/6")
Hack 3
The rolling dice example is a simulation because the number is programatically generated and no dice is truly rolled. The builtin pseudorandom number generator uses the computer's current precise time to generate a number between 0 and 1. This number is then multiplied/shifted by a constant to account for the range. This allows the "dice" to be rolled multiple times. An advantage of this simulation is that many trials (millions-billions) can be simulated and analytics can be performed immediately rather than physically gathering data and then performing statistics on it. An experiment would not be better in this situation because of the aforementioned advantages that the computer simulation provides.
Hack 4
import random
trials = 100000
sides = int(input("how many sides do you want the dice to have? "))
rolls = {}
for _ in range(trials):
roll = str(random.randint(1, sides))
if roll in rolls.keys():
rolls[roll] += 1
else:
rolls[roll] = 1
for (roll, weight) in rolls.items():
print("chance of rolling", roll.rjust(len(str(sides))) + ": " + str(weight) + "/" + str(trials))