What Does this Algorithm Do?

अब Quizwiz के साथ अपने होमवर्क और परीक्षाओं को एस करें!

PROCEDURE Mystery (x) { result ← 0 REPEAT 2 TIMES { REPEAT 3 TIMES { result ← x + result } } RETURN result } Which of the following expressions is equivalent to the value returned from Mystery(x)?

2 * 3 * x

In the program below, the initial value of a is 0 and the initial value of b is 1. IF (b = 0) { IF (b = 1) { DISPLAY ("Karel") } } ELSE { IF (a = 1) { DISPLAY ("Tracy") } ELSE { DISPLAY ("Dog") } DISPLAY ("Turtle") } What is displayed as a result of running this program?

Dog Turtle

PROCEDURE Mystery (word, list) { FOR EACH item IN list { IF (item = word) { RETURN (true) } } RETURN (false) } Which of the following best describes the behavior of the Mystery PROCEDURE?

Return whether or not word is in list

Consider the code segment below. PROCEDURE Mystery (number) { RETURN ((number MOD 2) = 0) } Which of the following best describes the behavior of the Mystery PROCEDURE?

Returns whether or not number is even

PROCEDURE Mystery (x) { result ← 0 REPEAT x TIMES { result ← result + 1 } RETURN result } Which of the following expressions is equivalent to the value returned from Mystery(x)?

x

PROCEDURE Mystery (x) { result ← 0 REPEAT 5 TIMES { result ← x + result } RETURN result } Which of the following expressions is equivalent to the value returned from Mystery(x)?

x * 5

Consider the code segment below. PROCEDURE Mystery (number) { DISPLAY ("WOW") REPEAT number TIMES { DISPLAY ("!") } } What is the result of calling the Mystery procedure with an input of 3?

WOW ! ! !

PROCEDURE Mystery (x, y) { result ← 0 REPEAT y TIMES { REPEAT x TIMES { result ← result + 1 } } RETURN result } Which of the following expressions is equivalent to the value returned from Mystery(x, y)?

y * x

Consider the code segment below. You can assume that Mystery returns either true or false, and Input_List_From_User asks the user for several values and returns them as a list. inputList ← Input_List_From_User () resultList ← [] FOR EACH item in inputList { IF (Mystery (item)) { APPEND (resultList, item) } } Based on the code segment, how would you best describe the value of resultList?

resultList contains all items from inputList that met the Mystery condition

Consider the code segment below. what ← 1 does ← what + 1 the ← what + does + 3 fox ← the + what say ← 3 result ← what + does + the + fox + say DISPLAY (result) Based on the code segment, what is displayed after running the program?

19

Consider the code segment below. x = RANDOM (1, 10) y = RANDOM (10, 20) DISPLAY (x = y) Which of the following best describes the behavior of the the code?

The program could display either true or false

Consider the code segment below. temp ← x x ← y y ← temp Based on the code segment, how would you best describe what the program is doing to variable x and variable y?

The program swaps the value of x and y

Consider the code segment below. You can assume that Input_List_From_User asks the user for several values and returns them as a list. inputList ← Input_List_From_User () resultList ← [] FOR EACH item in inputList { APPEND (resultList, Mystery (item)) } Based on the code segment, how would you best describe the value of resultList?

resultList contains the result of calling the Mystery procedure on every item in inputList

PROCEDURE Mystery (word, list) { x ← 0 y ← 0 FOR EACH item IN list { IF (item = word) { x ← x + 1 } ELSE { x ← 0 } IF (x > y) { y ← x } } RETURN (y) } What is the value of Mystery("karel", ["karel", "karel", "tracy", "karel", "karel", "karel", "tracy"])

3

Consider the code segment below. DISPLAY ("What is your name?") name ← INPUT () DISPLAY ("Hello") DISPLAY (name) What is displayed as a result if the user inputs "Karel" to the program?

What is your name? Hello Karel


संबंधित स्टडी सेट्स

Positive, Comparative, Superlative Latin

View Set

Interview Prep: Behavioural Questions

View Set

Pediatrics Practice Exam Questions

View Set

Chapter 12 Fluids & Electrolytes

View Set