题目
题目
单项选择题

Question at position 9 If the missing lines are correctly filled in, the program should continuously ask the user for a number until the user enters a number below zero where the program will give a warning. If they enter a number below zero again at any point after their warning, the program will stop. Below is an example output of the program, where bolded text is input to the program: Enter number: 4Valid!Enter number: -1Warning!Enter number: 0Valid!Enter number: -2 [table] 1  warning_given = False2 keep_running = True3 4  while keep_running:5 number = int(input('Enter number: '))6 if # ( code WILL go here ) :7 if # ( code WILL go here ) :8 keep_running = False9 else:10 warning_given = True11 print('Warning!') 12 else:13 print('Valid!') [/table] Which of the following options is the correct missing code? (Code filled in has been bolded.)6 if warning_given:7 if number < 0:6 if number >= 0: 7  if warning_given:6 if number < 0:7 if not warning_given:6 if number < 0: 7  if warning_given:Clear my selection

选项
A.6      if warning_given: 7          if number < 0:
B.6      if number >= 0:               7          if warning_given:
C.6      if number < 0: 7          if not warning_given:
D.6 if number < 0:              7          if warning_given:
查看解析

查看解析

标准答案
Please login to view
思路分析
We start by understanding the intended control flow inside the loop. The code structure shows a nested if: the outer if at line 6 leads to an inner if at line 7, and based on the inner condition either stops the loop or sets a warning and prints a message. This implies that when the user enters a negative number, we first check whether a prior warning has already been issued. If there has been a previous warning, we should stop the loop; otherwise, we should issue a warning and continue. Option 1 (A): 6 if number < 0: 7 if warning_given: This arrangement matches the described logic: the outer check tes......Login to view full explanation

登录即可查看完整答案

我们收录了全球超50000道考试原题与详细解析,现在登录,立即获得答案。

类似问题

更多留学生实用工具

加入我们,立即解锁 海量真题独家解析,让复习快人一步!