MacOS VSCode Python安装程序



当我运行除您的打印("Hello,World"(之外的任何操作时,终端会打印以下内容:

Traceback (most recent call last):
File "/usr/local/Cellar/python@3.10/3.10.8/Frameworks/Python.framework/Versions/3.10/lib/python3.10/runpy.py", line 196, in _run_module_as_main
return _run_code(code, main_globals, None,
File "/usr/local/Cellar/python@3.10/3.10.8/Frameworks/Python.framework/Versions/3.10/lib/python3.10/runpy.py", line 86, in _run_code
exec(code, run_globals)
File "/Users/juliuseners/.vscode/extensions/ms-python.python-2022.16.1/pythonFiles/lib/python/debugpy/adapter/../../debugpy/launcher/../../debugpy/__main__.py", line 39, in <module>
cli.main()
File "/Users/juliuseners/.vscode/extensions/ms-python.python-2022.16.1/pythonFiles/lib/python/debugpy/adapter/../../debugpy/launcher/../../debugpy/../debugpy/server/cli.py", line 430, in main
run()
File "/Users/juliuseners/.vscode/extensions/ms-python.python-2022.16.1/pythonFiles/lib/python/debugpy/adapter/../../debugpy/launcher/../../debugpy/../debugpy/server/cli.py", line 284, in run_file
runpy.run_path(target, run_name="__main__")
File "/Users/juliuseners/.vscode/extensions/ms-python.python-2022.16.1/pythonFiles/lib/python/debugpy/_vendored/pydevd/_pydevd_bundle/pydevd_runpy.py", line 321, in run_path
return _run_module_code(code, init_globals, run_name,
File "/Users/juliuseners/.vscode/extensions/ms-python.python-2022.16.1/pythonFiles/lib/python/debugpy/_vendored/pydevd/_pydevd_bundle/pydevd_runpy.py", line 135, in _run_module_code
_run_code(code, mod_globals, init_globals,
File "/Users/juliuseners/.vscode/extensions/ms-python.python-2022.16.1/pythonFiles/lib/python/debugpy/_vendored/pydevd/_pydevd_bundle/pydevd_runpy.py", line 124, in _run_code
exec(code, run_globals)
File "/Users/juliuseners/pythondir/Chapter 1.py", line 14, in <module>
if dis>0:
TypeError: '>' not supported between instances of 'function' and 'int'

我没能解决这个问题,以前有人碰到过这个吗?

尝试使用homebrews的建议手动更改PATH,但不知何故,我无法让它发挥作用。

编辑:我正在添加我试图在下面运行的代码:

import math
#The quadratic is luckily solved for all coefficients a,b,c except for a=0: this diqualifies the equation as quadratic. 
#I write the function based on following formula: x=(-b+/-sqrt(b^2-4*a*c))/2a
a=input("Enter a: ")
b=input("Enter b: ")
c=input("Enter c: ")
def findmyroots(a,b,c):
dis=b*b-4*a*c
sqrtdis=math.sqrt(abs(dis))
if dis>0:
print("The roots are:")
print((-b+sqrtdis)/(2*a))
print((-b-sqrtdis)/(2*a))
elif dis==0:
print("The roots are:")
print((-b)/(2*a))
else:
print("Roots are lateral")
if a==0:
print("Write a real quadratic please..")
else:1
findmyroots(a,b,c)

的几个问题

  1. 您的if块需要缩进才能位于函数内部
  2. 您的输入需要转换为数字,因为您不能对字符串类型进行数学运算

相反:

import math
#The quadratic is luckily solved for all coefficients a,b,c except for a=0: this diqualifies the equation as quadratic. 
#I write the function based on following formula: x=(-b+/-sqrt(b^2-4*a*c))/2a
#Problem #2: These have to be numeric otherwise your math will throw an error. I'm wrapping in `int` as an example
a=int(input("Enter a: "))
b=int(input("Enter b: "))
c=int(input("Enter c: "))
def findmyroots(a,b,c):
dis=b*b-4*a*c
sqrtdis=math.sqrt(abs(dis))
#Problem #1: Indentation. This all needs to be inside the function. 
if dis>0:
print("The roots are:")
print((-b+sqrtdis)/(2*a))
print((-b-sqrtdis)/(2*a))
elif dis==0:
print("The roots are:")
print((-b)/(2*a))
else:
print("Roots are lateral")
if a==0:
print("Write a real quadratic please..")
else:
findmyroots(a,b,c)

我不知道你对二次公式的实现是否正确(我已经20多年没有关心这些东西了(,但这段代码运行起来不会出错。

相关内容

最新更新