缩进
缩进
掌握 Python 语言编写的基本格式中的缩进。
知识点出处:详述(5);知识块2|CCF 编程能力等级认证 C++&Python 认证标准(CCF编程能力等级认证标准_C++ & Python_一至八级)(https://gesp.ccf.org.cn/101/1008/10012.html)
本知识点的讲解文案待补(Track D3)。以下为该知识点下的历年真题。
下面Python代码的相关说法,正确的是( )。
for i in range(1, 10):
if i % 2 == 0:
continue
else:
print(i, end = "#")
print(i,"END")
下面Python代码用于求1到N之和,N为正整数。因为 range() 中为 N+1,因此是1到N且包含N之和。( )
N = int(input("请输入正整数:"))
total = 0
for i in range(1, N + 1):
total += i
print(total)
原文保真说明:原卷印刷错误 1 处(照原卷保留,未作修改)
原卷印刷如此版式题干 · 第 4 行
原卷作
for i in range(1, N + 1): total += i,常规写法应为for i in range(1, N + 1): total += i原卷第 4 行 `total += i` 与 `for` 齐平、没有循环体缩进(文本层、列位重建、第 6 页 600 dpi 裁图 crops/p06-tf04-tight-6.png 像素左缘均一致),照原卷转写。