题目
多项填空题
Question at position 6 The code blocks below have been scrambled. The program should help the user decided what activity they do. If the user is tired, and its after 9pm, the user should play video games. If the user is tired, and its before 9pm, the user should take a nap. If the user is not tired, and its after 9pm, the user should cook dinner. If the user is not tired, and its before 9pm, the user should work out. Which of the following is the correct order of the code blocks?Top label: Code blocks:Code blocks:position 11[input]Position 1. Reorder Choice: time = 10tired = falsetime = 10tired = falseposition 22[input]Position 2. Reorder Choice: if time < 9: print("take a nap") if time < 9: print("take a nap")position 33[input]Position 3. Reorder Choice: else: print("play video games") else: print("play video games")position 44[input]Position 4. Reorder Choice: else:else:position 55[input]Position 5. Reorder Choice: if time < 9: print("work out") if time < 9: print("work out")position 66[input]Position 6. Reorder Choice: else: print("cook dinner") else: print("cook dinner")position 77[input]Position 7. Reorder Choice: if tired:if tired:Bottom label: null
选项
A.
B.
C.
D.
E.
F.
G.
查看解析
标准答案
Please login to view
思路分析
To tackle the scrambled code blocks, we first think about the intended overall decision structure. The program must decide an activity based on two variables: tired (whether the user is tired) and time (whether it is before or after 9). The correct logic is a two-level conditional: first check tired, then, inside each branch, check time. Concretely, the flow should be:
- If tired is true:
- If time < 9, print nap
- Else, print play video games
- If tired is false:
- If time < 9, print work out
- Else, print cook dinner
Now let’s examine the given options as pieces that could fit into that intended structure, noting what each piece contributes or lacks.
Option 1: "time = 10\ntired = false"
- This block establishes the initial state for the two variables. It is a reasonable first step because the subsequent conditional logic will rely on these values. However, on its own it does not perform any decision or output; it merely sets variables. In a complete program, this would typically appear at the top before any if statements.
Option 2: " if time < 9: print(\"take a nap\") if time < 9: prin......Login to view full explanation登录即可查看完整答案
我们收录了全球超50000道考试原题与详细解析,现在登录,立即获得答案。
类似问题
What is the output of the following code snippet if the cost contains 100: if cost > 150 : discount = 0.8 * costelse : discount = costprint("Your cost is:", discount)
The example program in the video has three possible outcomes depending on the following levels of radiation exposure: . Less than 0.5 sieverts . Greater than or equal to 0.5 but less than 4 sieverts . Greater than or equal 4 sieverts Which statement is used to capture an exposure value greater than or equal to 0.5 but less than 4 sieverts?
In a two-way if-else statement, when is the else block executed?
What is the purpose of the following code snippet?
更多留学生实用工具
希望你的学习变得更简单
加入我们,立即解锁 海量真题 与 独家解析,让复习快人一步!