安全问答

安全问答是一个知识全球问答,包含丰富的问答知识

首页 常规 游戏 娱乐 科技 程序员

怎样用for语句实现求1+3+5++100的和方法

  • 日期: 2028-08-01
  • 标签: 时尚

可以使用for循环从1到100,每次加2,累加到一个变量中,最后输出这个变量的值即可。

代码如下:

sum = 0
for i in range(1, 101, 2):
    sum += i
print(sum)

输出结果为:

2500
怎样用for语句实现求1+3+5++100的和方法

原文地址: https://www.cveoy.top/t/topic/6Gb 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录

  • 上一篇: If Britain sent 15000 soldiers to invade anapolis from sea in 1861 to help confederates and were countered by 70000 union troops led by hooker34000 confederates led by Lee was marching towards anapoli
  • 下一篇: 英雄联盟会员

© 2019 • 2025 - 安全问答 站长邮箱:wxgpt@qq.com    ICP备案/许可证号:豫ICP备2024104334号-2