3.16 Hacks
These are my 3.16 Hacks.
import random
status = "in"
while status != "out":
chooseCorner = input("What corner do you choose?")
corner = random.randint(1,4)
if int(chooseCorner) == corner:
status = "out"
print("You chose corner number " + chooseCorner + " and you're OUT")
else:
print("You chose corner number " + chooseCorner + " and are still in!")
Simulation idea: flipping 10 coins to see how many coins land on tails and how many on heads.
Advantages: Fast, consistantly random
Disadvantages: Dos not account the possibility of coins landing on their sides
An experiment is better because I can't assume the coins are fair just like in the simulation.
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")
Rolling Dice Simulation: User first picks a number of die that they want to roll. The range should be from 1 to 6. From there, the program checks the number that is inputted and then rolls the number of die the user has picked. Process:
- Choose a random number between 1 and 6.
- Repeat this for the number of die chosen in the beginning.
- The results of the random numbers generated are then outputted to the user in a list.
def parse_input(input_string):
if input_string.strip() in {"1", "2", "3","4", "5", "6"}:
return int(input_string)
else:
print("Please enter a number from 1 to 6.")
raise SystemExit(1)
import random
def roll_dice(num_dice):
roll_results = []
for _ in range(num_dice):
roll = random.randint(1, x) # increased range of random number chosen
roll_results.append(roll)
return roll_results
num_dice_input = input("How many dice do you want to roll? [1-6] ")
x = int(input("Please enter the number of sides you want the dice to have.")) # variable for sides the dice should have
num_dice = parse_input(num_dice_input)
roll_results = roll_dice(num_dice)
print("you rolled:", roll_results)
This output of the code will change with each run of it since the conditions can be altered.