Khan Academy- Compsci Principles: Simulations

Lakukan tugas rumah & ujian kamu dengan baik sekarang menggunakan Quizwiz!

A game developer is working on a basketball playing game. This incomplete code segment simulates a player attempting a 3-pointer shot: shotMade ← false IF (<MISSING CONDITION>) { shotMade ← true score ← score + 3 DISPLAY("Score!") } ELSE { DISPLAY("Miss!") } The code should give the player a 40% chance of making the shot. Which of these can replace <MISSING CONDITION> so that the code works as intended? 👁️Note that there are 2 answers to this question.

1. RANDOM(1, 100) <= 40 2. RANDOM(1, 5) <= 2

A digital artist is writing a program to draw a garden. This is a segment of the code that draws a single flower: xPos ← RANDOM(10, 380) height ← RANDOM(40, 160) FLOWER("red", xPos, 180, height) The code relies on the FLOWER() procedure, which accepts four parameters for the flower's color, x position, y position, and height. Here's what's drawn from one run of the program:

1.A flower at an x position of 10 and a height of 160 2.A flower at an x position of 50 and a height of 40

A digital artist is writing a program to draw a landscape with a randomly generated mountain range. This code draws a single mountain: xPos ← RANDOM(4, 240) height ← RANDOM(70, 120) drawMountain(xPos, 80, height) The code relies on the drawMountain() procedure, which accepts three parameters for the mountain's x position, y position, and height. Here's what's drawn from one run of the program:

1.A mountain at an x position of 4 and a height of 120 2.A mountain at an x position of 180 and a height of 110

A city government would like to make their streets more bike-friendly with features such as protected bike lanes. However, government officials are concerned about the effect on traffic flow. They hire a software consultant agency to develop a simulation of the traffic after the proposed changes. What are the most likely benefits of creating a computer simulation of the proposal? 👁️Note that there are 2 answers to this question.

1.Once it is developed, the simulation can run at a faster speed than a real-life experiment. 2.The simulation can try the addition of even more bike lanes without incurring significant extra cost for each lane added.

A game developer is working on a soccer video game. This incomplete code segment is run when a player attempts a goal from outside the 6 yard box: inGoal ← false IF (<MISSING CONDITION>) { inGoal ← true DISPLAY("Goal!") } ELSE { DISPLAY("Miss!") } At that distance, the code should give the player a 30% chance of making the goal. Which of these can replace <MISSING CONDITION> so that the code works as intended?

1.RANDOM(1, 10) <= 3 2.RANDOM(1, 100) <= 30

A web developer is creating an online lottery scratch card. This incomplete code segment decides whether the player wins a prize: IF (<MISSING CONDITION>) { awardAmount ← 10 } The code should only give the player a 3% chance of winning a prize. Which of these can replace <MISSING CONDITION> so that the code works as intended? 👁️Note that there may be multiple answers to this question.

1.RANDOM(1, 100) <= 3 2.RANDOM(1, 100) > 97

A game developer is working on a basketball playing game. This incomplete code segment simulates a player taking a shot: shotMade ← false IF (<MISSING CONDITION>) { shotMade ← true DISPLAY("Score!") } ELSE { DISPLAY("Miss!") } The developer wants to give this player a 75% chance of making the shot. Which of these can replace <MISSING CONDITION> so that the code works as intended? 👁️Note that there are 2 answers to this question.

1.RANDOM(1, 100) <= 75 2.RANDOM(1, 4) <= 3

The following code simulates the life cycle of a monarch butterfly. stage ← "egg" daysAsEgg ← 4 daysAsLarvae ← 12 daysAsPupa ← 12 daysAsAdult ← 36 daysInStage ← 0 REPEAT UNTIL (stage = "death") { IF (stage = "egg" AND daysInStage ≥ daysAsEgg) { stage ← "larvae" daysInStage ← 0 } IF (stage = "larvae" AND daysInStage ≥ daysAsLarvae) { stage ← "pupa" daysInStage ← 0 } IF (stage = "pupa" AND daysInStage ≥ daysAsPupa) { stage ← "adult" daysInStage ← 0 } IF (stage = "adult" AND daysInStage ≥ daysAsAdult) { stage ← "death" daysInStage ← 0 } daysInStage ← daysInStage + 1 DISPLAY(lifeState) } Which details are excluded from this simulation?

1.Some Monarch butterflies remain in larvae form for 8 days and others for 15 days. 2.Monarch butterflies that migrate live longer than monarchs that do not.

The following code simulates changing the temperature of water. temperatureC ← -15 waterStage ← "solid" meltingPoint ← 0 boilingPoint ← 100 REPEAT UNTIL (waterStage = "gas") { temperatureC ← temperatureC + 1 IF (temperatureC > boilingPoint) { waterStage ← "gas" } ELSE { IF (temperatureC > meltingPoint) { waterStage ← "liquid" } } } Which details are excluded from this simulation?

1.The boiling point of water varies based on the atmospheric pressure. 2.Water can exist as both a solid (ice) and as a liquid at 0 degrees celsius.

The following code simulates the fuel burned by the Saturn V rocket in the first stage of launch: weight ← 2800000 engineFuelPerSec ← 2578 numSeconds ← 165 numEngines ← 5 fuelUsed ← 0 REPEAT numSeconds TIMES { fuelBurned ← numEngines * engineFuelPerSec fuelUsed ← fuelUsed + fuelBurned weight ← weight - fuelBurned } DISPLAY(fuelUsed) DISPLAY(weight) Which details are excluded from this simulation? 👁️Note that there are 2 answers to this question.

1.The rocket burned different amounts of fuel per second at each stage of launch. 2.The rocket engines burned different amounts of two types of fuel (liquid oxygen and RP-1) each second.

Ashlynn is an industrial engineer who is trying to design a safer parachute. She creates a computer simulation of the parachute opening at different heights and in different environmental conditions. What are advantages of running the simulation versus an actual experiment? 👁️Note that there are 2 answers to this question.

1.The simulation can test the parachute design in a wide range of environmental conditions that may be difficult to reliably reproduce in an experiment. 2.The simulation can be run more safely than an actual experiment.

e following code simulates a hurricane moving hour-by-hour based on predicted wind directions: hourlyWindDirections ← ["N", "N", "E", "E", "S"]; windSpeed ← 5 hurricaneLat ← 33 hurricaneLng ← 47 FOR EACH (direction IN hourlyWindDirections) { IF (direction = "N") { hurricaneLat ← hurricaneLat - 0.1 * windSpeed } IF (direction = "S") { hurricaneLat ← hurricaneLat + 0.1 * windSpeed } IF (direction = "E") { hurricaneLng ← hurricaneLng - 0.1 * windSpeed } IF (direction = "W") { hurricaneLng ← hurricaneLng + 0.1 * windSpeed } } Which variables hold values that vary during the course of this simulation? 👁️Note that there are 2 answers to this question.

1.hurricaneLng 2.hurricaneLat

The following code simulates a piece of bread turning into toast: temperature ← 350 breadColor ← "white" moistureContent ← 30 numMinutes ← 10 REPEAT numMinutes TIMES { IF (moistureContent > 0) { moistureContent ← moistureContent - temperature/30 } ELSE { IF (breadColor = "white") { breadColor ← "yellow" } ELSE { breadColor ← "brown" } } } Which variables hold values that vary during the course of this simulation?

1.moistureContent 2.breadColor

The following code simulates the spread of a secret throughout a small town of gossipy individuals. whoKnowsSecret ← 1 interactionsPerDay ← 6 townPopulation ← 140 numDays ← numDays + 1 REPEAT UNTIL (whoKnowsSecret ≥ townPopulation) { whoKnowsSecret ← whoKnowsSecret * interactionsPerDay; numDays ← numDays + 1 } DISPLAY (numDays) Which variables hold values that vary during the course of this simulation?

1.whoKnowsSecret 2.numDays

An indie game developer is making a grid-based game and using code to randomly spawn dogs on the game grid. The following code spawns a dog: row ← RANDOM(3, 5) col ← RANDOM(2, 4) DOG(row, col) The procedure DOG draws the dog in a 5x5 grid, where the first parameter represents which horizontal row to draw it in, and the second parameter represents which vertical column to draw it in. The rows and columns are both numbered 1 through 5. Which of these represents the possible spawn squares for the dog?

3x3 square starting at the bottom middle

Sylvia is an industrial engineer working for a sporting goods company. She is developing a baseball bat that can hit balls with higher accuracy and asks their software engineering team to develop a simulation to verify the design. Which of the following details is most important to include in this simulation?

Accurate accounting for the effect of wind conditions on the movement of the ball

What is a simulation?

An abstraction of a real world phenomenon that includes some details and excludes others.

Deborah is creating a simulation to show the effect of rainfall on blades of grass. The following code segment simulates five blades of grass growing during seven days: 1: blades ← [0, 0, 0, 0, 0] 2: rainPerDays ← [2, 0, 1, 2, 3, 1, 0] 3: FOR EACH dailyRain IN rainPerDays { 4: FOR EACH blade IN blades { 5: IF (dailyRain ≥ 1) { 6: blade ← blade + 0.3 7: } 8: } 9: } How can she change the simulation so that each blade of grass grows at a variable rate?

Change line 6 to: blade ← blade + (0.3 * RANDOM(1, 2))

The following code segment simulates a race between two horses: raceLength ← 200 horse1 ← 0 horse2 ← 0 REPEAT UNTIL (horse1 ≥ raceLength OR horse2 ≥ raceLength) { horse1 ← horse1 + (RANDOM(1, 2) * 2) horse2 ← horse2 + (RANDOM(1, 1) * 2) } IF (horse1 = horse2) { DISPLAY("tie") } ELSE { IF (horse1 > horse2) { DISPLAY("Horse 1 won") } ELSE { DISPLAY("Horse 2 won") } } Which statement best describes the variability in this simulation?

Horse 1 races at a variable speed while horse 2 races at the same speed throughout the race.

What is always true of a simulation of a natural phenomenon?

It abstracts away some details of the real world.

A biologist puts tracking devices on birds all over the world and records the geographical coordinates of their movement. They then use that data to create a computer simulation that predicts the territory of a bird based on an initial geographic location. What is a benefit of the computer simulation?

It can be run for a wide range of initial values.

A hair care products company decides to use computer simulation to develop a new anti-dandruff conditioner. The simulation helps them choose the best ingredients, the ratio to combine them at, and the optimal amount of time to leave the conditioner in the hair. When they do user testing to find out how well the conditioner works on real hair, they see mixed results. Most of the testers reported less dandruff after, but the testers with curly hair absolutely hated what it did to their curls. What was most likely true about the simulation?

It did not include a representative range of hair types.

The following code simulates the spread of virus particles throughout a room in response to two people breathing and speaking. numCopies ← 0 numMinutes ← 10 people ← ["breathing", "breathing"] REPEAT numMinutes TIMES { FOR EACH person IN PERSONS { IF (person = "breathing") { numCopies ← numCopies + 20 } ELSE { IF (person = "speaking") { numCopies ← numCopies + 200 } } IF (RANDOM(1, 10) < 5) { IF (person = "speaking") { person ← "breathing" } ELSE { person ← "speaking" } } } DISPLAY(numCopies) }; Why is this simulation considered an abstraction?

It is a simplification of a more complex phenomena that captures some aspects and leaves out others

The following code simulates the movement of a golf ball in the air after it's been hit. initialVelocity ← 44 accelFromGravity ← -9.8 x ← 0 y ← 0 t ← 0 REPEAT UNTIL (y < 0) { x ← initialVelocity * t; y ← (initialVelocity * t) + ((accelFromGravity * (t*t)) / 2) DISPLAY(x) DISPLAY(y) t ← t + 1 } Which statement best describes why this simulation is an abstraction?

It leaves out details that do not effect the results as much, such as air resistance or golf ball material.

The following code simulates the feeding of 4 fish in an aquarium while the owner is on a 5-day trip: numFish ← 4 foodPerDay ← 20 foodLeft ← 160 daysStarving ← 0 REPEAT 5 TIMES { foodConsumed ← numFish * foodPerDay foodLeft ← foodLeft - foodConsumed IF (foodLeft < 0) { daysStarving ← daysStarving + 1 } } Why is this simulation considered an abstraction?

It simplifies a real-world scenario into something that can be modeled in code and executed on a computer.

A programmer is creating a simulation of a city where natural disasters can randomly occur. This incomplete code segment simulates a Godzilla disaster: IF (<MISSING CONDITION>) { cityHealth ← cityHealth - 30 disasterMode ← "godzilla" } The code should only give Godzilla a 2% chance of storming the city. Which of these can replace <MISSING CONDITION> so that the code works as intended?

RANDOM(1, 100) <= 2

A mobile game developer is programming a kitty simulator. This incomplete code segment determines whether the kitty will meow: IF (<MISSING CONDITION>) { DISPLAY("meow!") } The kitty should only meow 4% of the time. Which of these can replace <MISSING CONDITION> so that the code works as intended?

RANDOM(1, 100) <= 4

A company is developing a driving simulator to help emergency responders understand how to drive a wide range of trucks, just in case the responders find themselves in a situation where it's necessary. What detail would be least important to include in the simulation?

Roadside landscape that's textured based on recent satellite imagery

Dominic is an industrial designer who's developing an office chair that is more comfortable for tall individuals. He hires a software engineering firm to develop a simulation that can simulate the chair used by a person working at a desk, and then come up with an estimate of the resulting comfort level. Which detail is least necessary for this simulation?

The range of colors available for the chair's fabric

A researcher gathers data about the effect of Advanced Placement®︎ classes on students' success in college and career, and develops a simulation to show how a sequence of AP classes affect a hypothetical student's pathway. Several school administrators are concerned that the simulation contains bias favoring high-income students, however. Which of the following statements is true?

The simulation may accidentally contain bias due to the exclusion of details.

A hospital develops a computer simulation to train doctors how to converse with their patients about how they're feeling. The simulation includes 3D animated patients that respond to the doctor, based on a data set of actual patient responses. The doctors all train using the simulation and the hospital evaluates the quality of their patient conversations for a month after the simulation. They discover that the doctors are conversing better with many patients, but they are conversing worse with patients who aren't fluent in the doctor's language. That's when they realize the simulation contains bias favoring native speakers. What should the hospital do about the bias in the simulation?

They should add details to the simulation that better represent the diversity of the doctors' patients.

A digital artist is writing a program to draw a face. This is the part of the code that draws the eyes and pupils: eyeSize ← RANDOM(5, 20) CIRCLE("white", 20, 20, eyeSize) CIRCLE("white", 40, 20, eyeSize) pupilSize ← RANDOM(2, 5) CIRCLE("black", 20, 20, pupilSize) CIRCLE("black", 40, 20, pupilSize) The code relies on the CIRCLE() procedure from a drawing library, which accepts four parameters for the circle's fill color, x position, y position, and diameter. Here's what's drawn from one run of the program:

Two equally-sized eyes ranging in size, with a minimum size of 5 pixels and a maximum size of 20 pixels. Each eye has a black pupil that ranges in size from a minimum of 2 pixels to a max of 5 pixels.

An indie game developer is making a frog-catching game and using code to randomly spawn frogs on the game grid. The following code spawns a frog: row ← RANDOM(2, 5) col ← RANDOM(2, 3) FROG(row, col) The procedure FROG draws the frog in a 5x5 grid, where the first parameter represents which horizontal row to draw it in, and the second parameter represents which vertical column to draw it in. The rows and columns are both numbered 1 through 5. Which of these represents the possible spawn squares for the frog?

Vertical Rectangle- height is 4, width is 2

Jack is trying to plan his financial future using an online tool. The tool starts off by asking him to input details about his current finances and career. It then lets him choose different future scenarios, such as having children. For each scenario chosen, the tool does some calculations and outputs his projected savings at the ages of 35, 45, and 55. Would that be considered a simulation and why?

Yes, it's a simulation because it is an abstraction of a real world scenario that enables the drawing of inferences.

Kassidy develops a simulation of campfire smoke for a short film. The following code segment is responsible for fading particles away: 1: particles ← [100, 100, 100, 1100] 2: 3: FOR EACH particle IN particles { 4: particle ← particle - 1 5: } A particle with a value of 100 displays at full opacity and a particle with a value of 0 is invisible. She can use the following mathematical procedures: NameDescriptionMIN(a, b)Returns the smaller of the two arguments.MAX(a, b)Returns the greater of the two arguments.POW(a, b)Returns a raised to the power of b.RANDOM(a, b)Returns a random integer from a to b, including a and b. What line of code could replace line 4 to introduce variability into the simulation?

particle ← particle - RANDOM(1, 5)


Set pelajaran terkait

CH: 4 Patient Rights & Legal Issues

View Set

Impact of Changes on a DCF and WACC

View Set

Chapter 1-3 Pearson Dynamic Study Set

View Set

Evolution: quick or progressive?

View Set

Physical Geology - Online Lab Quiz 10

View Set

Конституція України

View Set