第10789题 单选题
关于Python实现数列-1+2+3-4+...计算的代码判断,以下说法正确的是?

Python编程求数列 -1+2+3-4+5+6-7+8+9-10+11+12-13+...... 之值。如输入4,则计算1到4(包含1和4)的和,规律如数列所示。待判断的参考代码:

N = int(input("请输入正整数: "))
tnt = 0
for i in range(1, N + 1):
    if i % 3 == 1:
        tnt += -i
    else:
        tnt += i
print(tnt)
{{ option.label }}
子题{{ index + 1 }} {{ child.type_label }}
{{ option.label }}
✓ 正确 ◐ 部分正确 ✗ 错误
程序运行统计
暂无判题统计
提交{{ questionInfo.stats ? questionInfo.stats.submit_count : 0 }}次 正确率{{ statsAccuracy }}%
答案解析