Docsity

Khan Academy Programming Study Guide List, Study Guides, Projects, Research of Computer Science

Toggle sidebar
bg1
1 / 68
Khan Academy Programming Study Guide List
1.
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?:
PI * (radius * radius) *
(height / 3)
2.
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?:
"Udupi",
"The Flying
Falafel", "Gaumenkitzel", "Rojbas Grill", "Platano", "Cafe Nostos"
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
pf2a
pf2b
pf2c
pf2d
pf2e
pf2f
pf30
pf31
pf32
pf33
pf34
pf35
pf36
pf37
pf38
pf39
pf3a
pf3b
pf3c
pf3d
pf3e
pf3f
pf40
pf41
pf42
pf43
pf44

Partial preview of the text

Download Khan Academy Programming Study Guide List and more Study Guides, Projects, Research Computer Science in PDF only on Docsity!

1 / 68

Khan Academy Programming Study Guide List

  1. 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?: PI * (radius * radius) * (height / 3)
  1. 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?: "Udupi", "The Flying Falafel", "Gaumenkitzel", "Rojbas Grill", "Platano", "Cafe Nostos"

2 / 68

  1. 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?: phrase: The custom phrase entered by the user

4 / 68 Which of these code segments correctly sets the value of canRide?

5 / 68 =NAote that there are 2 answers to this question.: IF (riderHeight e 4 8 ) { canRide • true } ELSE { canRide • false } IF (riderHeight < 48) { canRide • false } ELSE { canRide • true }

  1. 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! " 9 ) 10: } 11: IF (player2Shot = 2) 12: { 13: DISPLAY("Player 2 missed! " 9 ) 14: } 15: IF (player1Shot = 1 AND player2Shot = 1) 16: {

7 / 68

Unfortunately, this code is incorrect; the REPEAT UNTIL loop never stops repeating. Where would you add code so that the game ends when expected? =NAote that there are 2 answers to this question.: Between line 9 and 10 Between line 13 and 14

  1. 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? =NAote that there may be multiple answers to this question.: stepsPerMin • stepsPerDay / hoursAwake / 60 stepsPerMin • (stepsPerDay / hoursAwake) / 60
  1. 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"

8 / 68

ELSE

10 / 68 MouseyBots, walking exactly into the squares where they're hiding. Which of these code segments accomplishes that goal?: REPEAT 2 TIMES { walkForward() turnRight()

11 / 68 walkForward() turnLeft() turnLeft() }

  1. Nuru writes this code to calculate the final cost of an item with a discount applied: price • 0. discount

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?: The arithmetic operations on floating- point numbers resulted in a round-ott error.

  1. 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) e5) { wordScore • wordScore
  • 3 } ELSE { IF (LEN(word) e4) { wordScore • wordScore
  • 2 } ELSE { IF (LEN(word) e3) { wordScore • wordScore
  • 1 } }

13 / 68 ber of characters in the string. What value will this program display?: 13

  1. 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 para-meters 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? =NAote that there may be multiple answers to this question.: 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
  2. Marius is writing a program that calculates physics formulas. His procedure calcGravForce should return the gravitational force between two objects at a certain radius from each other, based on this formula: F=G((m1m2)/r^2) 1 PROCEDURE calcGravForce (mass1, mass2, radius) 2 { 3 ,,,,space, space, space, spaceG • 6.674 * POWER(10, −11) 4 ,,,,space, space, space, spacemasses • mass1 * mass 5 ,,,,space, space, space, spaceforce • G * ( masses / POWER(radius,
    1. )

14 / 68

The procedure is missing a return statement, however. Part 1: Which line of code should the return statement be placed after?: After line 5

16 / 68 i • 10 REPEAT 11 TIMES

17 / 68

sum • sum

  • i i • i + 1 } Which description best describes what this program does?: This program sums up the integers from 10 to 20 (inclusive).
  1. 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 pres-sure. Part 1: When will the computer stop executing the code inside the REPEAT loop? =NAote that there may be multiple answers to this question.: When meanPressure is greater than 65 When ivFluid is greater than 2000 The computer wouldn't execute the code more than 5 times.
  2. This program uses a nested conditional to assign the variable

19 / 68 IF (x > y) { mystery • x - y } ELSE { IF (x < y) { mystery • y / x } ELSE { mystery • x + y } } If we set x to 32 and y to 8, what value will the mystery variable store after running this code?: 24

  1. The video sharing site YouTube originally stored the number of video views in a 32-bit signed integer. Then the viral hit "Gangnam Style" received more than 2,147,483,647 views (more than any other video at that time), and YouTube could not display an accurate number of views until they changed their code. What is the best explanation of what happened?: Integer overflow error
  2. Consider the following code snippet: DISPLAY (":") DISPLAY ("-") DISPLAY ("O") After the code runs, what is displayed?: : - O
  3. The following procedure calculates the area of a trapezoid and takes three parameters: the width of the first base, the width

20 / 68 of the second base, and the height of the trapezoid. PROCEDURE trapezoidArea (b1, b2, h) {