Docsity

Khan Academy Programming Study List, Exams of Computer Science

Toggle sidebar
bg1
Khan Academy Programming Study List
Joo-won is writing code to calculate the volume of a cone based on this formula:
Volume=(Pi(r)^2)(h/3)
He's testing his code on this cone:
The code starts with these variables, where radius represents rrr and height represents hhh:
radius ← 2
height ← 5
The built-in constant PI stores an approximation of PI
Which expression correctly calculates the volume? - ANS PI * (radius * radius) * (height / 3)
A local search website lets users create lists of their favorite restaurants.
When the user first starts, the website runs this code to create an empty list:
localFavs ← []
The user can then insert and remove items from the list.
Here's the code that was executed from one user's list making session:
APPEND(localFavs, "Udupi")
APPEND(localFavs, "The Flying Falafel")
APPEND(localFavs, "Rojbas Grill")
APPEND(localFavs, "Cha-Ya")
APPEND(localFavs, "Platano")
APPEND(localFavs, "Cafe Nostos")
INSERT(localFavs, 3, "Gaumenkitzel")
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe
pff
pf12
pf13
pf14
pf15
pf16
pf17
pf18
pf19
pf1a
pf1b
pf1c
pf1d
pf1e
pf1f
pf20
pf21
pf22
pf23
pf24
pf25
pf26
pf27
pf28
pf29

Partial preview of the text

Download Khan Academy Programming Study List and more Exams Computer Science in PDF only on Docsity!

Khan Academy Programming Study List

Joo-won is writing code to calculate the volume of a cone based on this formula: Volume=(Pi(r)^2)(h/3) He's testing his code on this cone: The code starts with these variables, where radius represents rrr and height represents hhh: radius ← 2 height ← 5 The built-in constant PI stores an approximation of PI Which expression correctly calculates the volume? - ANS PI * (radius * radius) * (height / 3) A local search website lets users create lists of their favorite restaurants. When the user first starts, the website runs this code to create an empty list: localFavs ← [] The user can then insert and remove items from the list. Here's the code that was executed from one user's list making session: APPEND(localFavs, "Udupi") APPEND(localFavs, "The Flying Falafel") APPEND(localFavs, "Rojbas Grill") APPEND(localFavs, "Cha-Ya") APPEND(localFavs, "Platano") APPEND(localFavs, "Cafe Nostos") INSERT(localFavs, 3, "Gaumenkitzel")

REMOVE(localFavs, 5) What does the localFavs variable store after that code runs? - ANS "Udupi", "The Flying Falafel", "Gaumenkitzel", "Rojbas Grill", "Platano", "Cafe Nostos" Alissa is programming an app called ShirtItUp, where users can customize a t-shirt with their own phrase on it. Which variable would she most likely use a string data type for? - ANS phrase: The custom phrase entered by the user This program uses a conditional to determine whether a child will have free or attached earlobes. if (fatherAllele = "G" OR motherAllele = "G") { earlobeType ← "free" } ELSE { earlobeType ← "attached" } In which situations will earlobeType be "free"? 👁️Note that there may be multiple answers to this question. - ANS When fatherAllele is "G" and motherAllele is "G" When fatherAllele is "G" and motherAllele is "g" When fatherAllele is "g" and motherAllele is "G" This short program displays the winning result in a ship naming contest:

This program simulates a game where two players try to make basketball shots. Once either player misses 5 shots, the game is over. 1: player1Misses ← 0 2: player2Misses ← 0 3: REPEAT UNTIL (player1Misses = 5 OR player2Misses = 5) 4: { 5: player1Shot ← RANDOM(1, 2) 6: player2Shot ← RANDOM(1, 2) 7: IF (player1Shot = 2) 8: { 9: DISPLAY("Player 1 missed! ☹") 10: } 11: IF (player2Shot = 2) 12: { 13: DISPLAY("Player 2 missed! ☹") 14: } 15: IF (player1Shot = 1 AND player2Shot = 1) 16: { 17: DISPLAY("No misses! ☺") 18: } 19: } Unfortunately, this code is incorrect; the REPEAT UNTIL loop never stops repeating. Where would you add code so that the game ends when expected? 👁️Note that there are 2 answers to this question. - ANS Between line 9 and 10

Between line 13 and 14 Nikki read that it's healthy to take 10,000 steps every day. She's curious how many steps that'd be per minute, walking from 10AM to 10PM, and is writing a program to figure it out. The program starts with this code: stepsPerDay ← 10000 hoursAwake ← 12 Which lines of code successfully calculate and store the steps per minute? 👁️Note that there may be multiple answers to this question. - ANS stepsPerMin ← stepsPerDay / hoursAwake / 60 stepsPerMin ← (stepsPerDay / hoursAwake) / 60 A gardener is writing a program to detect whether the soils for their citrus trees are the optimal level of acidity. IF (measuredPH > 6.5) { soilState ← "high" } ELSE { IF (measuredPH < 5.5) { soilState ← "low" } ELSE {

We want to program KittyBot so that she pounces on both of the MouseyBots, walking exactly into the squares where they're hiding. Which of these code segments accomplishes that goal? - ANS REPEAT 2 TIMES { walkForward() turnRight() walkForward() turnLeft() turnLeft() } Nuru writes this code to calculate the final cost of an item with a discount applied: price ← 0. discount ← 0. final ← price - discount They're surprised to see that final stores the value 0.49999999999999994 instead of 0.5. What is the best explanation for that result? - ANS The arithmetic operations on floating-point numbers resulted in a round-off error. The following code snippet processes a list of strings with a loop and conditionals: words ← ["cab", "lab", "cable", "cables", "bales", "bale"] wordScore ← 0 FOR EACH word IN words { IF (LEN(word) ≥ 5) { wordScore ← wordScore + 3 } ELSE {

IF (LEN(word) ≥ 4) { wordScore ← wordScore + 2 } ELSE { IF (LEN(word) ≥ 3) { wordScore ← wordScore + 1 } } } } DISPLAY(wordScore) The code relies on one string procedure, LEN(string), which returns the number of characters in the string. What value will this program display? - ANS 13 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: Which of these describes mountains that might be drawn from this program? 👁️Note that there may be multiple answers to this question. - ANS A mountain at an x position of 4 and a height of 120 A mountain at an x position of 180 and a height of 110

Which of these lines of code correctly calls the procedure to calculate the slope of this line? - ANS lineSlope(2, 1, 4, 3) Jace is making a simulation of conversations with his 2-year-old son. Here's the program: PROCEDURE yellNo () { DISPLAY ("NOOOO!") DISPLAY ("😭😭😭") } DISPLAY ("Can you wear your gloves?") yellNo () DISPLAY ("How about a scarf?") yellNo () DISPLAY ("What about this super soft hat?") yellNo () In total, how many times does this code call the yellNo procedure? - ANS 3 The code segment below uses a loop to repeatedly sum up numbers. sum ← 0 i ← 10 REPEAT 11 TIMES { sum ← sum + i i ← i + 1 }

Which description best describes what this program does? - ANS This program sums up the integers from 10 to 20 (inclusive). This program attempts to automate the process of giving fluids to a hospital patient to stabilize their blood pressure: ivFluid ← 0 meanPressure ← measureBP() REPEAT UNTIL (meanPressure > 65 OR ivFluid > 2000) { injectFluid(500) ivFluid ← ivFluid + 500 meanPressure ← measureBP() } The program relies on two methods built-in to the IV machine: Name Description injectFluid(amountML) Injects the given amount of fluid (in milliliters). measureBP() Returns a number representing the patient's mean arterial pressure. Part 1: When will the computer stop executing the code inside the REPEAT loop? 👁️Note that there may be multiple answers to this question. - ANS When meanPressure is greater than 65 When ivFluid is greater than 2000 The computer wouldn't execute the code more than 5 times. This program uses a nested conditional to assign the variable mystery to a value:

After the code runs, what is displayed? - ANS : - O The following procedure calculates the area of a trapezoid and takes three parameters: the width of the first base, the width of the second base, and the height of the trapezoid. PROCEDURE trapezoidArea (b1, b2, h) { result ← ((b1 + b2) * h) / 2 DISPLAY (result) } Here is a trapezoid with an unknown area: Which of these lines of code correctly calls the procedure to calculate the area of this trapezoid? 👁️Note that there may be multiple answers to this question. - ANS trapezoidArea (4, 7, 3) trapezoidArea (7, 4, 3) The following code segment uses lists to store and update the seven natural wonders of the world: sevenWonders ← ["Aurora", "Grand Canyon", "Great Barrier Reef", "Guanabara Bay", "Mount Everest", "Parícutin", "Victoria Falls"] sevenWonders[4] ← "Komodo" sevenWonders[6] ← "Table Mountain" After running that code, what does the sevenWonders list store? - ANS "Aurora", "Grand Canyon", "Great Barrier Reef", "Komodo", "Mount Everest", "Table Mountain", "Victoria Falls" Yelp provides a restaurant search feature on their website: The code to display the search filter and results relies on many variables. Which of these variables are storing a string data type? 👁️Note that there may be multiple answers to this question. - ANS category ← "japanese"

searchQuery ← "sushi" searchNear ← "94701" state ← "CA" sortBy ← "closest" A game programmer uses this nested conditional in their online Four Square game. IF (mouseX < 200 AND mouseY < 200) { currentSquare ← 1 } ELSE { IF (mouseX > 200 AND mouseY < 200) { currentSquare ← 4 } ELSE { IF (mouseX < 200 AND mouseY > 200) { currentSquare ← 2 } ELSE { IF (mouseX > 200 AND mouseY > 200) { currentSquare ← 3 } } } }

volume ← (4/3) * 3.14159 * (radius * radius * radius) He then discovers that the coding environment has a built-in constant for PI plus a number of useful mathematical procedures: Name Description add(n, m) Returns the addition of n to m. sqrt(n) Returns the square root of nnn. square(n) Returns the value of n^2n 2 n, start superscript, 2, end superscript. cube(n) Returns the value of n^3n 3 n, start superscript, 3, end superscript. pow(n, m) Returns the value of n^mn m n, start superscript, m, end superscript. How could the code be rewritten using the constant and procedures? 👁️Note that there are 2 answers to this question. - ANS volume ← (4/3) * PI * cube(radius) volume ← (4/3) * PI * pow(radius, 3) Dahlia is creating a program to display Morse code. This is what her program contains so far: PROCEDURE sendA () { DISPLAY ("• −") } PROCEDURE sendB () {

DISPLAY ("− • • •")

PROCEDURE sendC () { DISPLAY ("− • − •") } PROCEDURE sendD () { DISPLAY ("− • •") } PROCEDURE sendE () { DISPLAY ("•") } PROCEDURE sendF () { DISPLAY ("• • − •") } sendF () sendA () sendD () sendE () sendD () When this program executes, how many total calls does it make to the DISPLAY procedure? - ANS 5 Nyala is making a program to display a monster on the screen. This is her code for storing the monster's coordinates: x ← 55 y ← 82

finalCost ← itemCost + (-1 * couponAmount) finalCost ← (itemCost - couponAmount) The two programs below are both intended to display the total number of hours from a list of durations in minutes. Program 1: totalMins ← 0 durations ← [32, 56, 28, 27] FOR EACH duration IN durations { totalMins ← totalMins + duration } totalHours ← totalMins / 60 DISPLAY(totalHours) Program 2: totalMins ← 0 durations ← [32, 56, 28, 27] FOR EACH duration IN durations { totalMins ← totalMins + duration totalHours ← totalMins / 60 } DISPLAY(totalHours) Which of these statements best describes these two programs? - ANS Both programs display the correct total number of hours, but Program 2 unnecessarily repeats arithmetic operations.

Seth is writing a dialogue engine for an emergency preparedness game. The program relies on multiple string operations: Pseudocode Description CONCAT(string1, string2) Concatenates (joins) two strings to each other, returning the combined string. UPPER(string) Returns the string in uppercase. Here's a snippet of his code: yell ← "ahhhh" danger ← "fire!" emoted ← CONCAT(yell, UPPER(danger)) What value does the emoted variable store? - ANS "ahhhhFIRE!" Elsie is looking through her classmate's program and sees a procedure called heightenEmotions: PROCEDURE heightenEmotions(myEmotion) { moreEnergy ← CONCAT(myEmotion, "!!!") moreVolume ← UPPER(moreEnergy) RETURN moreVolume } That procedure manipulates strings using two built-in procedures, CONCAT for concatenating two strings together, and UPPER for converting a string to uppercase. Elsie then sees this line of code: heightenEmotions("im mad") After that line of code runs, what will be displayed on the screen? - ANS Nothing will be displayed This list represents the top runners in a marathon, using their bib numbers as identifiers: