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)
标签:求和,max1,sum3,sum2,sum1,range,python3.2,print,最值 来源: https://www.cnblogs.com/lma0702/p/11107467.html