首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何使用Python3.x中内置的数学模块?

如何使用Python3.x中内置的数学模块?
EN

Stack Overflow用户
提问于 2011-03-29 09:58:33
回答 1查看 588关注 0票数 0

我是一个初级程序员,从Python开始。我试图在我的程序中使用math.log10(x),但是一直收到错误消息"NameError:名称‘数学’没有定义“。在我打字的时候会弹出智能感知,所以看起来我应该可以使用它了。到目前为止,我读过的指南中几乎没有提到如何正确地拉出一个模块,所以我有点迷茫。

这是我目前的程序:

代码语言:javascript
复制
print("Enter an integer 'n' that is greater than 1: ")
n = int(input())

Primes = [2]
 #List of Prime Numbers
Candidate = 3
 #Number tested for Primeness
Product = 1
 #Running product of prime numbers < n
Logarithm = True
 #Will be the log of the product of the primes
##Ratio = True
## #Will be the ratio of the Logarithm to n

while Primes[len(Primes)-1] <= n:
     #Continue only while Primes < n
IsPrime = True
i=0
while i < len(Primes):
    if Candidate%Primes[i] == 0:
        IsPrime = False
    else:
        Product = Product * Candidate
         #Multiplies the current product by the newest prime < n
    i = i + 1   
if IsPrime:
    Primes.append(Candidate)
     #Adds newest prime to the list
Candidate = Candidate + 1

Logarithm = math.log10(Product)

我知道这是一个非常初级的问题,但我需要帮助。谢谢!

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2011-03-29 10:00:51

在程序的顶部输入"import math“。

票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/5467083

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档