一、偶数和
# -*- coding: UTF-8 -*-
x=0
sum=0
for x in range(0,102,2):
sum = sum + x print(sum)
二、奇数和
# -*- coding: UTF-8 -*-
sum = 0
n = 100
while n > 0 :
if n%2==1:
sum = sum + n
n=n-1
else:
n=n-1
print(sum)
文章标签 1-101中所有的ou数python python 文章分类 Python 后端开发
一、偶数和
# -*- coding: UTF-8 -*-
x=0
sum=0
for x in range(0,102,2):
sum = sum + x print(sum)
二、奇数和
# -*- coding: UTF-8 -*-
sum = 0
n = 100
while n > 0 :
if n%2==1:
sum = sum + n
n=n-1
else:
n=n-1
print(sum)
Python从0到100(七):Python列表介绍及运用
一、Python语法#求出1-100的奇数和、偶数和sum_1 = 0sum_2 = 0for i in range(1,101): if i%2 ==0: sum_2 += i else: sum_1 += iprint("奇数和:",sum_1)print("偶数和:",sum_2)奇数和: 2500偶数和: 2550二、Java
举报文章
请选择举报类型
补充说明
0/200
上传截图
格式支持JPEG/PNG/JPG,图片不超过1.9M