(1)通过while 循环来求出1-100之和'''

(2)通过while 循环来求出1-100奇数之和'''

(3)通过while 循环来求出1-100偶数之和'''

1-101中所有偶数python python1到100偶数和_python 100以内偶数

1-101中所有偶数python python1到100偶数和_1-101中所有偶数python_02

1-101中所有偶数python python1到100偶数和_1-101中所有偶数python_03

奇数和

sum1=0
for i in range(1,101):
if i%2 != 0:
sum1=sum1+i
i+=1
print (sum1)

奇数之和

a=1
sum=0
while a<=100 :
sum+=a #sum =sum +a
a+=2
print (sum )

偶数和

a=1
sum=0
while a<=100:
if a%2==0:
sum+=a
a+=1
print (sum)

偶数和

a=0
sum=0
while a<=100 :
sum+=a #sum =sum +a
a+=2
print (sum )

题目:

1、求出100的偶数之和

2、求出100的奇数之和

3、用偶数之和减去奇数之和 '''

# a =0
# sum =0 #求和容器存放结果
# while a <=100:
# sum+=a
# a +=2
# print(sum) #2550 偶数之和
#
# c =1
# sum=0
# while c <=100:
# sum+=c
# c+=2
# print(sum) #2500 奇数之和
#
# l =0
# sum_o=0 #存放偶数的容器
# sum_j=0 #存放奇数的容器
# while l <=100:
# if l % 2==0:
# sum_o+=l
# else:
# sum_j+=l
# l+=1
# print(sum_o)
# print(sum_j)
# print(sum_o-sum_j)