for_in 循环初认识

#!/usr/bin/env python
#-*- coding:utf-8 -*-
sum_all=0
sum_odd=0#奇数和
sum_even=0#偶数和
for x in range(101):
    sum_all+=x
    if x%2==1:
        sum_odd+=x
    else:
        sum_even+=x

print("1-100累加和{0},奇数和{1},偶数和{2}".format(sum_all,sum_odd,sum_even))
================================================================================
输出:

1-100累加和5050,奇数和2500,偶数和2550


 

posted @ 2021-04-21 22:32  614_四爷  阅读(69)  评论(0编辑  收藏  举报