我是一个初级程序员,从Python开始。我试图在我的程序中使用math.log10(x),但是一直收到错误消息"NameError:名称‘数学’没有定义“。在我打字的时候会弹出智能感知,所以看起来我应该可以使用它了。到目前为止,我读过的指南中几乎没有提到如何正确地拉出一个模块,所以我有点迷茫。
这是我目前的程序:
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)我知道这是一个非常初级的问题,但我需要帮助。谢谢!
发布于 2011-03-29 10:00:51
在程序的顶部输入"import math“。
https://stackoverflow.com/questions/5467083
复制相似问题