2011-03-29 108 views
0

我是一个初学者程序员,从Python开始。我试图在我的程序中使用math.log10(x),但不断收到错误“NameError:name'math'未定义”。 当我打字时,智能感知弹出,所以看起来我应该可以使用它。到目前为止,我所读过的指南几乎没有提到如何正确地拉起一个模块,所以我有点失落。如何在Python 3.X中使用内置的数学模块?

这是我目前的计划:

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) 

我知道这是一个非常入门级的问题,但我可以使用帮助。谢谢!

+0

你用什么教程学习Python? – 2011-03-29 02:09:22

回答

2

在程序的顶部键入“导入数学”。

+0

谢谢!我知道这很简单...:/ – Artemis 2011-03-29 02:50:20