1.编写函数,输出1 ~ 100 中偶数之和。
2.编写函数,判断用户输入的3个数字是否能构成三角形的三条边。
如有用请采纳
def a():
s=0
for i in range(1,101):
if i%2==0:
s+=i
return s
a()
def san(a,b,c):
if a+b>c and a-b<c:
return True
else:
return False
san(3,4,5)
给两个简单额例子:
#第一题
lst = [i for i in range(1,101) if i%2==0]
print(sum(lst))
#第二题
edges = list(map(int, input().split(",")))
print(edges)
edges.sort()
print(edges)
if edges[0]+edges[1]>edges[2]:
print("输入的3个数字{edge}能构成三角形")
else:
print("输入的3个数字{edge}不能能构成三角形")
第一题:
i=1
sum=0
while i<=100:
if i%2==0:
sum+=i
i+=1
else:
i+=1
print("1-100之间所有偶数的和为%d"%sum)
第二题:
while 1 :
try:
a, b, c = map(int, input().split())
if a < b + c and b < a + c and c < a + b :
if a == b == c:
print("Equilateral triangle!")
elif a == b or a == c or b == c:
print("Isosceles triangle!")
else:
print("Ordinary triangle!")
else:
print("Not a triangle!")
except:
break