2011-03-29 44 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

相關問題