安全问答

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

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

Python 代码计算 1000 到 2000 的奇数和偶数之和

  • 日期: 2028-08-30
  • 标签: 常规

odd_sum = 0 # 奇数和 even_sum = 0 # 偶数和

for i in range(1000, 2001): if i % 2 == 0: even_sum += i else: odd_sum += i

print('1000 到 2000 中所有的奇数和为:', odd_sum) print('1000 到 2000 中所有的偶数和为:', even_sum)

Python 代码计算 1000 到 2000 的奇数和偶数之和

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

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

  • 上一篇: The Battle of Maine: A Forgotten Clash Between Britain and the Union
  • 下一篇: 不同国家碳排放政策综述:碳税与排放权交易

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