开发者

How does one use the built-in math module in Python 3.X?

I'm a beginner programmer, starting in Python. I'm attempting to use math.log10(x) in my program, but keep getting the error "NameError: name 'math' is not defined". The intellisense pops up while I'm typing, so it seems like I should be able to use it. The guides I've read so far have said little about how to properly pull up a module, so I'm kind of lost开发者_JAVA百科.

Here's my current program:

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)

I know this is a very entry level question, but I could use the help. Thank you!


type "import math" at the top of the program.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜