用python写对输入的两个数a,b求c,c满足关系式: c²=a²+b²
时间: 2023-03-22 07:03:18 浏览: 167
\u8fd9\u4e2a\u95ee\u9898\u662f\u4e00\u4e2a\u6570\u5b66\u95ee\u9898\uff0c\u9700\u8981\u5f00\u59cb\u5206\u6790\u6570\u5b66\u5b8c\u6574\u7684\u89e3\u9898\u8fdb\u884c\u89e3\u51b3\u3002\u9996\u5148\uff0c\u4f7f\u7528Python\u8bed\u8a00\u4e2d\u7684\u6570\u5b66\u5e93\u53ca\u8ba1\u7b97\u51fd\u6570\u6c42\u51fa a^2, b^2 \u548c c^2\uff0c\u7136\u540e\u5c06\u5b83\u4eec\u4e00\u4e0b\u5f62\u5f0f c^2 = a^2 + b^2 \u8fdb\u884c\u89e3\u51b3\uff0c\u4e3a\u4e0b\u9762\u7684Python\u4ee3\u7801\uff1a
```
import math
def pythagorean_theorem(a, b):
c_squared = a**2 + b**2
c = math.sqrt(c_squared)
return c
```
\u4f7f\u7528\u8fd9\u4e2a\u51fd\u6570\uff0c\u4f60\u53ef\u4ee5\u4f7f\u7528\u4e0a\u9762\u7684\u7b54\u6848\uff0c\u6d4b\u8bd5\u4e00\u4e0b a = 3\uff0cb = 4\uff0c\u5e76\u8c03\u7528 pythagorean_theorem \u51fd\u6570\uff0c\u8fd9\u6837\uff1a
```
a = 3
b = 4
c = pythagorean_theorem(a, b)
print(c)
```
\u8fd9\u4e2a\u7a0b\u5e8f\u5c06\u8fd4\u56de 5.0\uff0c\u8868\u793a\u4e86\u7b54\u6848 c = 5\uff0c\u8fd9\u4e0e\u4e0a\u9762\u6240\u4f7f\u7528\u7684\u516c\u5f0f\u4e00\u81f4\u3002
阅读全文