Python 测验 Python 测验


Python 测验 - 条件判断与循环

if None:
    print(“Hello”)
for i in [1, 0]:
    print(i+1)
i = sum = 0

while i <= 4:
    sum += i
    i = i+1

print(sum)
while 4 == 4:
    print('4')
for char in 'PYTHON STRING':
  if char == ' ':
      break

  print(char, end='')
  
  if char == 'O':
      continue
$(function() { code1= '
' + $("#py-qa-1").html() + '
'; code2= '
' + $("#py-qa-2").html() + '
'; code3= '
' + $("#py-qa-3").html() + '
'; code4= '
' + $("#py-qa-4").html() + '
'; code5= '
' + $("#py-qa-5").html() + '
'; $('#quiz').quiz({ counterFormat: '第 %current 题,共 %total 题', resultsFormat: '回答正确 %score 题,总共 %total 题!', nextButtonText: '下一题', finishButtonText: '完成', restartButtonText: '重新测验', questions: [ { 'q': code1 + '

以上代码输出的结果是?

', 'options': [ 'False', 'Hello', '没有任何输出', '语法错误' ], 'correctIndex': 2, 'correctResponse': '回答正确。', 'incorrectResponse': '回答错误,None 为 False,所以没有任何输出。' }, { 'q': '在 if...elif...else 的多个语句块中只会执行一个语句块?', 'options': [ '正确。', '错误。', '根据条件决定。', 'Pyhton 中没有 elif 语句。' ], 'correctIndex': 0, 'correctResponse': '回答正确。', 'incorrectResponse': '回答错误,在 if...elif...else 的多个语句块中只会执行一个语句块。' }, { 'q': code2 + '

以上代码输出结果为?

', 'options': [ '2
1', '[2, 1]', '2', '0' ], 'correctIndex': 0, 'correctResponse': '回答正确。', 'incorrectResponse': '回答错误,正确的是 输出 2 ,然后再输出 1。' }, { 'q': 'Python 中,for 和 while 可以有 else 语句?', 'options': [ '只有 for 才有 else 语句。', '只有 while 才有 else 语句。', 'for 和 while 都可以有 else 语句。', 'for 和 while 都没有 else 语句。' ], 'correctIndex': 2, 'correctResponse': '回答正确。', 'incorrectResponse': '回答错误,for 和 while 都可以有 else 语句。' }, { 'q': code3 + '

以上代码输出的结果是?

', 'options': [ '0', '10', '4', '以上结果都不对。' ], 'correctIndex': 1, 'correctResponse': '回答正确。', 'incorrectResponse': '回答错误,正确的为 10。' }, { 'q': code4 + '

以上代码输出的结果是?

', 'options': [ '输出一次 4。', '输出四次 4。', '无限次输出 4,直到程序关闭。', '语法错误。' ], 'correctIndex': 2, 'correctResponse': '回答正确。', 'incorrectResponse': '回答错误,正确的为无限次输出,直到程序关闭。' }, { 'q': '迭代输出序列时(如:列表)使用 for 比 while 更好?', 'options': [ '错误,while 比 for 更好。', '正确', '错误,while 不能用于迭代系列。', '错误,for 和 while 都不能用于迭代系列。' ], 'correctIndex': 1, 'correctResponse': '回答正确。', 'incorrectResponse': '回答错误,这个说法是正确的。' }, { 'q': '以下哪个描述是正确的?', 'options': [ 'break 语句用于终止当前循环。', 'continue 语句用于跳过当前剩余要执行的代码,执行下一次循环。', 'break 和 continue 语句通常与 if, if...else 和 if...elif...else 语句一起使用。', '以上说法都是正确的。' ], 'correctIndex': 3, 'correctResponse': '回答正确。', 'incorrectResponse': '回答错误,所有的描述的是正确的。' }, { 'q': code5 + '

以上代码输出的结果是?

', 'options': [ 'PYTHON', 'PYTHONSTRING', 'PYTHN', 'STRING' ], 'correctIndex': 0, 'correctResponse': '回答正确。', 'incorrectResponse': '回答错误,正确的为 PYTHON。' }, { 'q': '以下关于 pass 哪个描述是正确的?', 'options': [ 'Python 会忽略 pass 语句,就像忽略注释一样。', 'pass 语句会终止当前循环。', 'pass 不做任何事情,一般用做占位语句。', '以上说法都是正确的。' ], 'correctIndex': 2, 'correctResponse': '回答正确。', 'incorrectResponse': '回答错误,pass 不做任何事情,一般用做占位语句。' }, ] }); })

Python 测验 Python 测验