Notes For 3.16

  • Simulation: Imitation of a process, kinda of like an experiment in your computer.
  • Example of a simulation is games as it is just testing and running code technically.
  • Try to think of why a simulation would be helpful, this will allow you to see if a simulation is even necessary.
  • Advantages of simulations
    • Safer
    • cost effective
    • efficient
  • Disadvantages
    • Not as accurate
    • Data could be changing
  • Real life example: Four corners
  • For the four corners, there are many different outside variables that could change the outcome, such as Mr.Mortenson being able to hear people move, or maybe him even peeking and looking to see which number people choose.
  • Dice is an example of a good simulation as rolling a die could be done much more efficiently within a simulation.

Hacks

  • Create an idea for a simulation and describe it (you don’t actually have to code it just think about/answer the guiding questions).
    • One idea for a simulation is an engine testing simulation for airplanes. The simulation will run flights through different weather conditions where each weather condition having a different chance at causing a malfunction in the engine. The simulation will run until the engine fails and then print how many flights the engine lasted. This would allow mechanics to easily test different builds and allow them to make small changes without having to wait until a plane in real life fails.
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")
Welcome to the Simulations Quiz!

 True or False: Simulations will always have the same result. 
 A: True, 
 B: False
You said:  B
Correct!

 True or False: A simulation has results that are more accurate than an experiment 
 A: True, 
 B: False
You said:  B
Correct!

 True or False: A simulation can model real world events that are not practical for experiments 
 A: True, 
 B: False
You said:  A
Correct!

 Which one of these is FALSE regarding simulations 
 A: Reduces Costs, 
 B: Is safer than real life experiments, 
 C: More Efficient, 
 D: More accurate than real life experiments
You said:  D
Correct!

 Which of the following scenarios would be the LEAST beneficial to have as a simulation 
 A: A retail company wants to identify the item which sold the most on their website, 
 B: A restaurant wants to determine if the use of robots will increase efficiency, 
 C: An insurance company wants to study the impact of rain on car accidents, 
 D: A sports car company wants to study design changes to their new bike design 
You said:  A
Correct!

 Which of the following is better to do as a simulation than as a calculation 
 A: Keeping score at a basketball game, 
 B: Keeping track of how many games a person has won, 
 C: Determining the average grade for a group of tests, 
 D: Studying the impact of carbon emissions on the environment
You said:  D
Correct!
You scored:  6 /6

Hack #3

  • Describe the rolling dice simulation (answer guiding questions)
    • The rolling dice simulation chooses a random number from 1-6 which simulates the possible outcomes from rolling a standard 6 sided die. This is an example to a simulation as it imitates the process of rolling a die. The advantages is that this is purely random, not changed by small imperfections within one side of the die. A disadvantage is that it is not perfectly related to a die in the real world as it is actually random. I think that an experiment would be better as it would give more accurate results. ### Hack #4
  • Add a feature onto the rolling dice simulation above
    • ex: a 14-sided dice or expand the purpose of the simulation (hint: use conditionals to make dice part of a game/real life situation) I changed it so that you can roll a 13-sided die and roll up to 13 times. I also added different if-statements depending on the sum of the results.
def parse_input(input_string):
    if input_string.strip() in {"1", "2", "3","4", "5", "6", "7", "8", "9", "10", "11", "12", "13"}:
        return int(input_string)
    else:
        print("Please enter a number from 1 to 13.")
        raise SystemExit(1)

import random

def roll_dice(num_dice):
    roll_results = []
    for _ in range(num_dice):
        roll = random.randint(1, 13)
        roll_results.append(roll)
    return roll_results


num_dice_input = input("How many dice do you want to roll? [1-6] ")
num_dice = parse_input(num_dice_input)
roll_results = roll_dice(num_dice)
import math
if sum(roll_results) > 50:
    print("you rolled:", roll_results, "that is actually a lot") 
if sum(roll_results) < 50:
    print("you rolled:", roll_results, "wow thats it") 
you rolled: [8, 13, 1, 2, 10, 9, 8, 11, 2, 12, 2, 2, 5] that is actually a lot

Extra Credit

This is a simulation because it simulates picking a random destination to fly to. An advantage to this is it is actually random and you will see real "random" results, but a disadvantage to this is that it is not realistic at all. People would not randomly choose a destination so this has no real purpose. I think that an experiment would be more accurate to see where people would travel to.

import random
flight = random.randint(1,3)

if flight == 1:
    print("You are flying nowhere :(")
if flight == 2:
    print("You can fly to Rome!")
if flight == 3:
    print("You can fly wherever you want.")
You can fly wherever you want.