3.16 hacks/notes
these are the hacks for lesson 8
#
Hacks 1
One idea for a simulation is a flight simulator. It is better to code a flight simulator and test out planes in it than doing it in real life. IRL planes are very expensive compared to the endless simulations that can be run on a computer. A flight simulator is a simulation because it takes IRL factors (physics, engineering) and combines it into a computer program. A big disadvantage would be the fact that a simulation is not 100% accurate. I don't think an experiment would be better in this case. A real life experiment would cost too much money and time. The flight simulator would take in irl factors and combine it into a program. You can then input any situation and run it to get visual output.
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")
Hacks 3
Rolling dice simulation:
What makes it a simulation?
- It takes in the features of a die and represents those features in a code. You can then run the code and roll the die how many ever times you want(code: input the number of times you roll the die). You will then get to see the end result of your roll (code: returns the output).
Disadvantages and advantages?
- One advantage of this simulation is that you dont need a physical die. You have a virtual die which doesn't take up any physical space compared to an actual die (okay fine, a real die takes up a negligible amount). One disadvantage is the physical interaction and excitement of rolling a die. Unless you code a 3d simulation of a die, then you won't get that experience.
Would an experiment be better?
- Yes. For me, rolling a die in real life is a lot more suspenseful and satisfying than rolling it on a computer.
import random
/**
* ! Changed number of sides on a die to 14 and max number of rolls to 14
* @param args
* @throws Exception
*/
def parse_input(input_string):
if input_string.strip() in {"1","2","3","4","5","6","7","8","9","10","11","12","13","14"}:
return int(input_string)
else:
print("Please enter a number from 1 to 14.")
raise SystemExit(1)
def roll_dice(num_dice):
roll_results = []
for _ in range(num_dice):
roll = random.randint(1, 14)
roll_results.append(roll)
return roll_results
num_dice_input = input("How many dice do you want to roll? [1-14] ")
num_dice = parse_input(num_dice_input)
roll_results = roll_dice(num_dice)
print("you rolled:", roll_results)
Bonus:
For the bonus, I made a population simulation. This is a very basic simulation that does not take in factors such as infant mortality rate, fertility, and food. The initial population is 75 and the rate of growth is 1.0008% (daily). We can find the daily growth by multiplying population*growthrate and then subtracting population. One advantage is that it can let you predict future populations, allowing you to prepare for what's coming. One disadvantage is the lack of reality. You can only add so many factors, but in the end, it will still be somewhat inaccurate. In this case, I would say that a simulation is better than an experiment. Well, an experiment would be somewhat unethical.
population = 75
growthrate = 1.0008
day = 0
while population <= 10000:
population *= growthrate
day += 1
if day == 120:
day = 0
print(f"this month the total population is {population}")