问题001-1:请对输入三个整数a,b,c,判断能否以它们为三个边长构成三角形。若能,输出YES和面积,否则输出NO
a = float(input())
b = float(input())
c = float(input())
if a > 0 and b > 0 and c > 0: #判断边长是否为正
if (a + b > c) and (a + c > b) and (b + c > a): #判断是否可以为三角形
p = (a + b + c)/2.0
S = (p*(p - a)*(p - b)*(p - c))**0.5 #面积,海伦公式
print("YES, 边长为: a = {},b = {},c = {}, 面积为:{}".format(a,b,c,S))
else:
print("NO")
else:
print("NO")
问题001-2:可逆素数是将某素数的各位数字顺序颠倒后仍为素数的数,请编程并输出200以内的可逆素数
注意:1不是素数也不是合数
def GetReNums(n):
if ((n//100 ==0) & (n//10 ==0)):
num1 = n
num2 = n
else:
if ((n//100 ==0) & (n//10 !=0)):
num1 = n
num2 = n%10 * 10 + n//10
else:
num1 = n
num2 = n%100%10 * 100 +n//10%10*10 +n//100
return num1,num2
for n in range(2,200,1):
num1,num2 = GetReNums(n)
devn1 = 0
devn2 = 0
for i in range(2,num1,1):
if (num1%i ==0):
devn1 = devn1+1
for i in range(2,num2,1):
if (num2%i ==0):
devn2 = devn2+1
if ((devn1==0)&(devn2==0)):
print(n)
原文地址:https://www.cnblogs.com/bonnienote/p/9413016.html