Notes
- A simulation is an fake version of a process
- An experiment is made to make a discoverey
- Simulations are safer and cheaper but not as accurate
- Sometimes it can be advantagous for an experiment and sometimes for a simulaiton
- ## Hacks
- One simulation idea could be one for a business. They could simulate how much of a product would be bought or taken within a certain amount of time. They can determine how much product they need and how fast they need to make it. This is a simulation because they are not occuring in real life. It's advatages are that is can help save money however it is not completely accurate. This would be better than an exerpiment because it saves money. Another could be a video game such as "The Sims" which simulates a person.
- The dice rolling simulation simulates a dice. It asks the user to input how many dice they want to roll and then it gives the amount of outputs as the user inuted. So if the user inputted three there would be three outputs. Each of these inputs are a random number between 1-6 simulating the different sides. In real life the user would pick up how many dices they would want to roll then they would roll them. This is a simulation because it simulates a dice roll. Its advantages are that you don't need a dice. Its disadvantages are that it is not as fun. However the function is mostly the same. This would be much better as an experiment because it is more emersive. The main function of dices is board games which are made for fun so we have to maximize that aspect. The code firslty uses a parse inpu command to fetch the data that the user input which would be a number 1-6. Then the random library is imported. Through this the roll variable is set as a random integer 1-6 to simulate the dice's sides. Finally it is printed.
- I am adding a function to the dice. I am making it a game so every number corresponds to a certain space on a board game that changes the game. I also added an extra two sides to the dice and the number of dice increased by 2.
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")
def parse_input(input_string):
if input_string.strip() in {"1", "2", "3","4", "5", "6", "7", "8"}:
return int(input_string)
else:
print("Please enter a number from 1 to 8.")
raise SystemExit(1)
import random
def roll_dice(num_dice):
roll_results = []
for _ in range(num_dice):
roll = random.randint(1, 8)
roll_results.append(roll)
return roll_results
num_dice_input = input("How many dice do you want to roll? [1-8] ")
num_dice = parse_input(num_dice_input)
roll_results = roll_dice(num_dice)
print("you rolled:", roll_results)
for i in roll_results:
if i == 1:
print('Discard a card')
if i == 2:
print('Draw a card')
if i == 3:
print('Move back a space')
if i == 4:
print('Go back to start')
if i == 5:
print('Nothing happens')
if i == 6:
print('Lose a point')
if i == 7:
print('Gain a point')
if i == 8:
print('Skip to finish. ')
- For my extra credit hack I am making a simulation for feeding a certain amount of people at an event. You can input the amount of people that are going to be at the event and it chooses a random number from 1-3 to determine how much tacos each person will eat which will all ow us to determine how much to make. First the code takes the user input and splits it into indivdual values that equal one. Then each integer is multiplied by a random number 1-3 and then it adds the values for the number of tacos that need to be made.
import random
# prompt the user for a number
people = input("How many people do we need.")
# convert the input to an integer
people = int(people)
# create a list to store the individual numbers
numbers = []
# iterate over a range of numbers from 0 to the input number
for i in range(people):
# add the value 1 to the list
numbers.append(1)
# create a list to store the multiplied numbers
tacos = []
# iterate over each number in the list
for num in numbers:
# generate a random number between 1 and 3
factor = random.randint(1, 3)
# perform the multiplication
multiplied_num = num * factor
# add the multiplied number to the list of multiplied numbers
tacos.append(multiplied_num)
# add up all of the multiplied numbers
total = sum(tacos)
# print the total
print("We need", total, 'tacos')
import random
color = random.randint(1,8)
if color == 1 | 2 | 3:
print('Green')
elif color == 4 | 5:
print('Blue')
elif color == 6:
print('Purple')
elif color == 7:
print('Red')
elif color == 8:
print('Orange')