QUESTION IMAGE
Question
in order to make the sprite say \hi\ in this program, what must the programmer do?
a. delete the second speak function
b. rearrange the order of the modules
c. call the speak function
d. change the function parameter
Step1: Analyze the speak function
The speak function has a condition: if the word parameter is "bye", it executes one block; else, it repeats the num times. When calling speak with "hi", since "hi" ≠ "bye", it should repeat the num times. But currently, when calling speak with "hi", the num is 2. However, looking at the function, the code inside the else (which is for non - "bye" words) is a repeat block. But if we want the sprite to just say "hi" (not repeat based on the num for "hi" in a wrong way, maybe the intended behavior is that when we call the function for "hi", we want a simple say. But looking at the code structure, the problem is that for non - "bye" words (like "hi"), the code is in a repeat block. But if we assume that the repeat is an error (maybe a wrong parameter passing), and we look at the call call speak 2 "hi". If we change the first parameter (num) to 1 (a simple say), but since the options don't have that. Wait, re - analyzing: the function for "bye" has a simple say, for non - "bye" (like "hi") it's in a repeat. But if we call the speak function with "hi" and we want a simple say (like the "bye" case), but the code for non - "bye" is in a repeat. However, looking at the call call speak 2 "hi", if we change the function parameter (the num) to 1 (but since it's a multiple - choice and the options are given). Wait, no, re - checking: the function speak has two parameters: num and word. When we call call speak 2 "hi", in the function, since word = "hi" (≠ "bye"), it goes to the else part which is repeat num times (num = 2). But maybe the programmer intended that for non - "bye" words, it's a simple say (like the "bye" case but without repeat). But since it's a multiple - choice and looking at the options:
- Option A: Deleting the second speak function (the call to
speakwith "bye") won't help with "hi" being said correctly. - Option B: Rearranging the order of the modules (the two calls
call speak 2 "hi"andcall speak 3 "bye"). The order of calls just determines the order of execution. But the problem is with how "hi" is processed in the function. - Option C: The
call speakis already done. - Option D: The function has parameters num and word. When we call
speakwith "hi", if we change the num parameter (the first parameter) from 2 (which makes it repeat 2 times) to 1 (but in the code structure of the function, for non - "bye" words, if num = 1, it'srepeat 1 timewhich is equivalent to a simple say. So changing the function parameter (the num value when calling for "hi") is the solution.
Snap & solve any problem in the app
Get step-by-step solutions on Sovi AI
Photo-based solutions with guided steps
Explore more problems and detailed explanations
D. Change the function parameter