[英]I can't use "from math import sqrt" on Visual Studio Code
I'm new to this site, I'm recently trying to learn how to code in Python again, and now I'm doing an exercise that I could complete, but it's happening something that is annoying me.我是这个网站的新手,我最近正在尝试再次学习如何用 Python 编码,现在我正在做一个我可以完成的练习,但它发生了一些让我烦恼的事情。 I can import math successfully, but somehow, VSCode just doesn't want to recognize "from math import sqrt".我可以成功导入数学,但不知何故,VSCode 只是不想识别“从数学导入 sqrt”。 Here's my code so anyone can help me.这是我的代码,所以任何人都可以帮助我。 Thank you.谢谢你。
import math # (from math import sqrt would be here, but doesn't work so I put import math)
a = int(input('Digite o primeiro número: '))
b = int(input('Digite o segundo número: '))
c = a**2+b**2
resultado = math.sqrt(c)
print(f'O comprimento da hipotenusa é de {resultado}')
If you do from math import sqrt then you have imported only sqrt and not math.如果您执行 from math import sqrt ,那么您只导入了 sqrt 而不是 math。 So in this case resultado = math.sqrt(c)
should be resultado = sqrt(c)
instead.所以在这种情况下resultado = math.sqrt(c)
应该改为resultado = sqrt(c)
。
Mathias answered it in the comments; Mathias 在评论中回答了这个问题; thank you.谢谢你。
you dont need the math module, you can instead do:你不需要数学模块,你可以这样做:
c = (a**2+b**2)**0.5
as square rooting a number is equal to power it to 1/2.作为平方根,一个数字等于它的 1/2 次幂。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.