Lesson 15-16 Hacks
Lesson 16 Hacks
HACKS 1
Imagine a virtual world that resembles a city, with buildings, streets, and vehicles. The city is populated by virtual people, each with their own characteristics, behaviors, and goals. These virtual people, or "agents," can interact with each other and the environment in realistic ways.
Some possible goals for the agents could include:
-
Going to work or school
-
Running errands (e.g. grocery shopping, visiting the bank)
-
Socializing with other agents
-
Participating in leisure activities (e.g. going to the park, attending a concert)
In order to achieve their goals, the agents would need to navigate the city, make decisions, and interact with other agents and the environment. For example, an agent might decide to take the bus to work in the morning, but if they are running late they might choose to hail a taxi instead.
The simulation would include realistic physics and traffic rules, so that agents and vehicles move and behave in a believable way. The city would also include different types of buildings and landmarks, such as offices, shops, and parks.
As the simulation runs, the agents would go about their daily routines and interact with each other in various ways. The simulation could also include random events, such as traffic accidents or weather changes, to add an element of unpredictability and realism.
Overall, the simulation would provide a rich and realistic virtual world for the agents to inhabit and explore, and could be used to study and analyze the behavior of large groups of agents in a city-like environment.
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 simulation in Python is a program that generates a random number between 1 and 6, simulating the outcome of rolling a single six-sided die. The program may be used to simulate multiple rolls of the die and track the results, allowing the user to study the distribution of the outcomes and the probability of certain numbers being rolled. The program can be implemented using the built-in random module in Python, which provides a function for generating random numbers. To simulate rolling a die, the program would first import the random module, then use the random.randint() function to generate a random integer between 1 and 6, which would represent the outcome of the roll. The program could then output the result of the roll and continue to simulate additional rolls as desired.
import random
# Roll the 14-sided die
result = random.randint(1, 14)
# Output the result of the roll
print(f'The 14-sided die landed on {result}')
height = 100
#define the coefficient of restitution (bounciness) of the ball
cor = 0.7
#define the number of bounces
bounces = 10
#for the number of bounces
for i in range(bounces):
#calculate the height of the ball on this bounce
height = height * cor
#check if the ball is still above 0.01 units
if height < 0.01:
#end the simulation
break
#output the height of the ball on this bounce
print("Bounce", i+1, ": height =", height)
This simple simulation models the behavior of a ball being dropped and bouncing on the ground. The starting height, bounciness, and number of bounces can be adjusted to see how they affect the behavior of the ball. For example, increasing the bounciness will cause the ball to bounce higher, and increasing the number of bounces will cause the ball to bounce more times before coming to a stop.