题目
单项选择题
Question at position 8 If the missing lines are filled in correctly, the program should continuously take in input a character which will be concatenated to a word. However, if the character entered is in the list of vowels, it is NOT included in the concatenation, and the program ends. Below is an example output of the program, where bolded text is input to the program: Enter a character: TEnter a character: HEnter a character: EWord: TH [table] 1 vowels = ['A', 'E', 'I', 'O', 'U']2 word = ''3 keep_running = True4 5 while keep_running:6 character = input('Enter a character: ')7 if character in vowels:8 # code WILL go inside IF9 # code MAY go here10 # …11 # …12 print('Word:', word) [/table] Which of the following options is the correct missing code? (Code filled in has been bolded.) 7 if character in vowels:8 word = word + character9 else:10 keep_running = False7 if character in vowels:8 keep_running = False9 else:10 word = word + character7 if character in vowels:8 keep_running = False9 word = word + character7 if character in vowels:8 if keep_running:9 word = word + character10 else:11 keep_running = FalseClear my selection
选项
A.7 if character in vowels:
8 word = word + character
9 else:
10 keep_running = False
B.7 if character in vowels:
8 keep_running = False
9 else:
10 word = word + character
C.7 if character in vowels:
8 keep_running = False
9 word = word + character
D.7 if character in vowels:
8 if keep_running:
9 word = word + character
10 else:
11 keep_running = False
查看解析
标准答案
Please login to view
思路分析
Reframing the scenario in my own words helps set up the evaluation: the program reads characters, appends non-vowels to the word, and stops when a vowel is entered. The missing code must implement this behavior inside the loop, using the existing variables vowels and word.
Option 1:
7 if character in vowels:
8 word = word + character
9 else:
10 keep_running = False
This option concatenates the input character to the word when the character is a......Login to view full explanation登录即可查看完整答案
我们收录了全球超50000道考试原题与详细解析,现在登录,立即获得答案。
更多留学生实用工具
希望你的学习变得更简单
加入我们,立即解锁 海量真题 与 独家解析,让复习快人一步!