题目:
1.
2.
解题过程:
1.
单独创建一个MyTriangle模块
def isvalid(side1, side2, side3):
return area(side1, side2, side3)
def area(side1, side2, side3):
if side1 + side2 < side3 or side3 + side2 < side1 or side3 + side1 < side2:
print("无法构成三角形")
else:
print("可以构成三角形")
side_length = (side1 + side2 + side3) / 2
area_num = (side_length * (side_length - side1) * (side_length - side2) * (
side_length - side3)) ** 0.5
print(f"三角形的面积为:{area_num}")
调用MyTriangle模块
from MyTriangle import isvalid
def main():
side1, side2, side3 = eval(input("输入三条边: "))
return isvalid(side1, side2, side3)
main()
结果:
2.
def reverse():
number = eval(input("输入整数:"))
a = number // 1000
b = number // 100 % 10
c = number % 100 // 10
d = number % 10
reverse_num = str(d) + str(c) + str(b) + str(a)
return reverse_num
print(reverse())