我可以使用Visual Studio代码Python 3.8.0导入统计信息。我甚至可以看到intellisense选项的中位数、中位数低等等
import statistics as st
numbers = [0, -6, 10, 5, 8, 2, -12, 11, -2]
print(numbers)
numbers.sort()
print(numbers)
#[-12, -6, -2, 0, 2, 5, 8, 10, 11]
print("\nmedian of the numbers")
print(st.median(numbers))
然而,当我执行代码时,我在VisualStudio代码中得到了以下内容。 我做错了什么
[0, -6, 10, 5, 8, 2, -12, 11, -2]
[-12, -6, -2, 0, 2, 5, 8, 10, 11]
median of the numbers
Traceback (most recent call last):
File "d:/ProgrammingSource/Python/PracticeVarious/pracNumbers.py", line 14, in <module>
print(st.median(numbers))
AttributeError: module 'statistics' has no attribute 'median'
我确实把我的代码用在了Anaconda/Spyder和Anaconda/Jupyter中,它实际上起了作用。Jupyter没有Intellisense,Spyder有时也不会显示不同的选项。可视化代码让我可以看到不同的选项
我并不是要讨论使用哪种Python IDE。只是想找出我在VisualStudio代码中键入的错误
我确实发现了一个类似的问题,但此人没有具体说明他们使用了哪种Python。 我的3.8.0版本如下:
PS D:\ProgrammingSource\Python\PracticeVarious> python
Python 3.8.0 (tags/v3.8.0:fa919fd, Oct 14 2019, 19:37:50) [MSC v.1916 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>>
当前工作目录中可能已经有一个名为statistics.py的文件。检查此目录中是否存在-
它显示错误,因为它不是导入默认统计信息模块,而是导入statistics.py。要解决此问题,只需重命名名为statistics.py的文件
相关问题 更多 >
编程相关推荐