python3.2求和与最值

#1到100求和
sum1=0
for x in range(101):
sum1=sum1+x
print(sum1)

 

#1到100偶数求和
sum2=0
for x in range(0,101,2):
print(x)
sum2=sum2+x
print("结果1:",sum2)

 

#1到100奇数求和
sum3=0
for x in range(1,101,2):
print(x)
sum3=sum3+x
print("结果2:",sum3)


#数列求最值
a=[32,423,423,432,555,56,65,756,856,52,52]
max1=a[0]
for x in range(0,len(a)-1):
if max1<=a[x+1]:
max1=a[x+1]
print("最大值是:",max1)
min1=a[0]
for x in range(0,len(a)-1):
if min1>=a[x+1]:
min1=a[x+1]
print("最小值是:",min1)

 

posted @ 2019-06-29 18:37  千钧蚁  阅读(270)  评论(0编辑  收藏  举报