我是一名初学程序员,从Python开始。我正在尝试在我的程序中使用math.log10(x),但不断收到错误“NameError:name'matth'未定义”。 当我打字时,intellisense弹出,所以看起来我应该可以使用它。到目前为止我读过的指南几乎没有说明如何正确地拉出模块,所以我有点迷失。
这是我目前的计划:
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 :(得分:2)
在程序顶部输入“import math”。