100% tevredenheidsgarantie Direct beschikbaar na je betaling Lees online óf als PDF Geen vaste maandelijkse kosten 4,6 TrustPilot
logo-home
Tentamen (uitwerkingen)

khan academy programming unit test exam 2022/2023

Beoordeling
-
Verkocht
-
Pagina's
58
Cijfer
A+
Geüpload op
29-11-2022
Geschreven in
2022/2023

A digital artist is creating an animation with code. Their code needs to convert polar coordinates to cartesian coordinates, using these formulas: x = r × cos( θ )y = r × sin( θ )x=r×cos(θ)y=r×sin(θ) The environment provides these built-in procedures: NameDescriptionsin(angle)Returns the sine of the given (angle)Returns the cosine of the given angle. In their code, theta represents the current angle and r represents the current radius. Which of these code snippets properly implements the conversion formulas? x ← r * cos(theta) y ← r * sin(theta) Yong is making a program to help him figure out how much money he spends eating. This procedure calculates a yearly cost based on how much an item costs, and how many times a week he consumes it: PROCEDURE calcYearlyCost(numPerWeek, itemCost) { numPerYear ← numPerWeek 52 yearlyCost ← numPerYear itemCost RETURN yearlyCost } Yong wants to use that procedure to calculate the total cost of his breakfast beverages: hot tea, which he drinks 5 days a week and costs $2.00 boba, which he drinks 2 days a week and costs $6.00 Which of these code snippets successfully calculates and stores their total cost? ️Note that there are 2 answers to this question. totalCost ← calcYearlyCost(2, 6.00) + calcYearlyCost(5, 2.00) teaCost ← calcYearlyCost(5, 2.00) bobaCost ← calcYearlyCost(2, 6.00) totalCost ← teaCost + bobaCost The following code snippet processes a list of strings with a loop and conditionals: words ← ["belly", "rub", "kitty", "pet", "cat", "water"] counter ← 0 FOR EACH word IN words { IF (FIND(word, "e") = -1 AND FIND(word, "a") = -1) { counter ← counter + 1 } } DISPLAY(counter) The code relies on one string procedure, FIND(source, target), which returns the first index of the string target inside of the string source, and returns -1 if target is not found. What value will this program display? 2 Lucie is developing a program to assign pass/fail grades to students in her class, based on their percentage grades. Their college follows this grading system: PercentageGrade70% and abovePASSLower than 70%FAIL The variable percentGrade represents a student's percentage grade, and her program needs to set grade to the appropriate value. Which of these code segments correctly sets the value of grade? ️Note that there are 2 answers to this question. IF (percentGrade ≥ 70) { grade ← "PASS" } ELSE { grade ← "FAIL" } IF (percentGrade 70) { grade ← "FAIL" } ELSE { grade ← "PASS" } The following numbers are displayed by a program: 4 5 5 6 The program code is shown below, but it is missing three values: COUNTER, AMOUNT, and STEP. i ← COUNTER REPEAT AMOUNT TIMES { DISPLAY(i) DISPLAY(i + 1) i ← i + STEP } Given the displayed output, what must the missing values be? COUNTER = 4, AMOUNT = 2, STEP = 1 This program uses a conditional to predict the hair type of a baby. IF (fatherAllele = "C" AND motherAllele = "C") { hairType ← "curly" } ELSE { IF (fatherAllele = "s" AND motherAllele = "s") { hairType ← "straight" } ELSE { hairType ← "wavy" } } In which situations will hairType be "wavy"? ️Note that there may be multiple answers to this question. When fatherAllele is "s" and motherAllele is "C" When fatherAllele is "C" and motherAllele is "s"

Meer zien Lees minder

Voorbeeld van de inhoud

khan academy programming unit test

A digital artist is creating an animation with code. Their code needs to convert polar coordinates to
cartesian coordinates, using these formulas:

x = r × cos( θ )\\y = r × sin( θ )x=r×cos(θ)y=r×sin(θ)

The environment provides these built-in procedures:

NameDescriptionsin(angle)Returns the sine of the given angle.cos(angle)Returns the cosine of the given
angle.

In their code, theta represents the current angle and r represents the current radius.

Which of these code snippets properly implements the conversion formulas? correct answerx ← r *
cos(theta)

y ← r * sin(theta)



Yong is making a program to help him figure out how much money he spends eating.

This procedure calculates a yearly cost based on how much an item costs, and how many times a week
he consumes it:

PROCEDURE calcYearlyCost(numPerWeek, itemCost) { numPerYear ← numPerWeek * 52 yearlyCost ←
numPerYear * itemCost RETURN yearlyCost }

Yong wants to use that procedure to calculate the total cost of his breakfast beverages:

hot tea, which he drinks 5 days a week and costs $2.00

boba, which he drinks 2 days a week and costs $6.00

Which of these code snippets successfully calculates and stores their total cost?

👁️Note that there are 2 answers to this question. correct answertotalCost ← calcYearlyCost(2, 6.00) +
calcYearlyCost(5, 2.00)



teaCost ← calcYearlyCost(5, 2.00) bobaCost ← calcYearlyCost(2, 6.00) totalCost ← teaCost + bobaCost



The following code snippet processes a list of strings with a loop and conditionals:

words ← ["belly", "rub", "kitty", "pet", "cat", "water"] counter ← 0 FOR EACH word IN words { IF
(FIND(word, "e") = -1 AND FIND(word, "a") = -1) { counter ← counter + 1 } } DISPLAY(counter)

,The code relies on one string procedure, FIND(source, target), which returns the first index of the string
target inside of the string source, and returns -1 if target is not found.

What value will this program display? correct answer2



Lucie is developing a program to assign pass/fail grades to students in her class, based on their
percentage grades.

Their college follows this grading system:

PercentageGrade70% and abovePASSLower than 70%FAIL

The variable percentGrade represents a student's percentage grade, and her program needs to set grade
to the appropriate value.

Which of these code segments correctly sets the value of grade?

👁️Note that there are 2 answers to this question. correct answerIF (percentGrade ≥ 70) { grade ←
"PASS" } ELSE { grade ← "FAIL" }



IF (percentGrade < 70) { grade ← "FAIL" } ELSE { grade ← "PASS" }



The following numbers are displayed by a program:

4556

The program code is shown below, but it is missing three values: <COUNTER>, <AMOUNT>, and <STEP>.

i ← <COUNTER> REPEAT <AMOUNT> TIMES { DISPLAY(i) DISPLAY(i + 1) i ← i + <STEP> }

Given the displayed output, what must the missing values be? correct answer<COUNTER> = 4,
<AMOUNT> = 2, <STEP> = 1



This program uses a conditional to predict the hair type of a baby.

IF (fatherAllele = "C" AND motherAllele = "C") { hairType ← "curly" } ELSE { IF (fatherAllele = "s" AND
motherAllele = "s") { hairType ← "straight" } ELSE { hairType ← "wavy" } }

In which situations will hairType be "wavy"?

👁️Note that there may be multiple answers to this question. correct answerWhen fatherAllele is "s" and
motherAllele is "C"



When fatherAllele is "C" and motherAllele is "s"

,Darrell is making a program to track his grades. He made the mistake of using the same variable name to
track 3 different test grades, though. Here's a snippet of his code:

a ← 89 a ← 97 a ← 93

What will be the value of a after this code runs? correct answer93



The following procedure calculates the slope of a line and takes 4 numeric parameters: the x coordinate
of the first point, the y coordinate of the first point, the x coordinate of the second point, and the y
coordinate of the second point.

PROCEDURE lineSlope (x1, y1, x2, y2) { result ← (y2 - y1) / (x2 - x1) DISPLAY (result) }

This graph contains a line with unknown slope, going through the points [1, 1][1,1]open bracket, 1,
comma, 1, close bracket and [3, 4][3,4]open bracket, 3, comma, 4, close bracket:

\small{1}1\small{2}2\small{3}3\small{4}4\small{1}1\small{2}2\small{3}3\small{4}4yyxx

Graph with line going through 2 marked points [1, 1] and [3, 4]

Which of these lines of code correctly calls the procedure to calculate the slope of this line? correct
answerlineSlope(1, 1, 3, 4)



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? correct answer"Udupi", "The Flying Falafel",
"Gaumenkitzel", "Rojbas Grill", "Platano", "Cafe Nostos"



Aden is working on a program that can generate domain names.

His program uses the following procedure for string concatenation:

PseudocodeDescriptionconcatenate(string1, string2)Concatenates (joins) two strings to each other,
returning the combined string.

, These variables are at the start of his program:

company ← "cactus" tld1 ← "com" tld2 ← "io"

Which line of code would store the string "cactus.io"? correct answername2 ← concatenate(company,
concatenate(".", tld2))



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. correct answerBetween line 9 and 10



Between line 13 and 14



This short program displays the winning result in the Greenpeace whale naming contest:

DISPLAY ("Mister") DISPLAY ("Splashy") DISPLAY ("Pants")

Part 1: How many statements are in the above program?



Part 2: What does the program output? correct answer3



Mister Splashy Pants



Nanami is researching how much software engineers make. She's writing a program to convert yearly
salaries into hourly rates, based on 52 weeks in a year and 40 hours in a week.

The program starts with this code:

salary ← 105000 wksInYear ← 52 hrsInWeek ← 40

Which lines of code successfully calculate and store the hourly rate?

Documentinformatie

Geüpload op
29 november 2022
Aantal pagina's
58
Geschreven in
2022/2023
Type
Tentamen (uitwerkingen)
Bevat
Vragen en antwoorden

Onderwerpen

Maak kennis met de verkoper

Seller avatar
De reputatie van een verkoper is gebaseerd op het aantal documenten dat iemand tegen betaling verkocht heeft en de beoordelingen die voor die items ontvangen zijn. Er zijn drie niveau’s te onderscheiden: brons, zilver en goud. Hoe beter de reputatie, hoe meer de kwaliteit van zijn of haar werk te vertrouwen is.
PassPointExams Brown University
Bekijk profiel
Volgen Je moet ingelogd zijn om studenten of vakken te kunnen volgen
Verkocht
174
Lid sinds
3 jaar
Aantal volgers
170
Documenten
2506
Laatst verkocht
11 maanden geleden
Where preparation meets precision

A results-driven exam shop delivering exam-ready questions, rationales, and pass-focused study guides. Designed to help students hit the exact point where passing happensno fluff, no overload.

4,1

49 beoordelingen

5
31
4
5
3
5
2
2
1
6

Populaire documenten

Recent door jou bekeken

Waarom studenten kiezen voor Stuvia

Gemaakt door medestudenten, geverifieerd door reviews

Kwaliteit die je kunt vertrouwen: geschreven door studenten die slaagden en beoordeeld door anderen die dit document gebruikten.

Niet tevreden? Kies een ander document

Geen zorgen! Je kunt voor hetzelfde geld direct een ander document kiezen dat beter past bij wat je zoekt.

Betaal zoals je wilt, start meteen met leren

Geen abonnement, geen verplichtingen. Betaal zoals je gewend bent via iDeal of creditcard en download je PDF-document meteen.

Student with book image

“Gekocht, gedownload en geslaagd. Zo makkelijk kan het dus zijn.”

Alisha Student

Veelgestelde vragen