内容目录
# 写代码 - while 循环 # 使用 while 循环实现输出 2 - 3 + 4 - 5 + 6 ... + 100 的和,即 2-100 的偶数加,奇数减
""" # 审题问题和思路不对 # total = 0 # num = 1 # while num < 101: # if num % 2 == 0: # total += num # print("01:", total) # else: # total -= num # print("02:", total) # num += 1 # print("03:", total) # 审题问题和思路不对 total = 0 num = 1 while num < 101: if num % 2 == 0: # total += num # print("01:", total) print("01:您的分数为:{}".format(total + num)) else: # total -= num print("02:您的分数为:{}".format(total - num)) num += 1 print("03:", total) # 审题清晰和思路打开,format 不对 total = 0 num = 2 while num < 101: if num % 2 == 0: # total += num # print("01:", total) print("01:您的分数为:{}".format(total + num)) else: # total -= num print("02:您的分数为:{}".format(total - num)) num += 1 print("03:", total) """ # 最终完成 total = 0 num = 2 while num < 101: if num % 2 == 0: # 2 偶数加,奇数减 total += num # 0+2-3+4 print("01:", total) # print("01:您的分数为:{}".format(total + num)) else: total -= num # 0+2-3+4-5 print("02:", total) # print("02:您的分数为:{}".format(total - num)) num += 1 print("03:", total) # 0+2-3+4-5+6-7+8-9...
相关文章
- Anaconda所有历史版本下载(0)
- ThinkPad x13 Gen1傲腾H10重装系统的麻烦(0)
- Win10系统电脑进入安全模式的四种方法,让你轻松应对各种问题(0)
- 使用Jetson_benchmark进行性能测试(0)
- 【Python】修改Windows中 pip 的缓存位置与删除 pip 缓存(1)