借助於sympy.primepi()方法,我們可以找到小於或等於給定數的質數數。
用法: primepi(n)
參數:
n – 它表示要計算素數計數的數字。
返回值:返回小於或等於n的質數個數。
示例1:
# import primepi() method from sympy
from sympy import primepi
n = 10
# Use primepi() method
count_primes = primepi(n)
print("The number of prime numbers less than or equal to {} is {}".format(n, count_primes))
輸出:
The number of prime numbers less than or equal to 10 is 4
示例2:
# import primepi() method from sympy
from sympy import primepi
n = 150
# Use primepi() method
count_primes = primepi(n)
print("The number of prime numbers less than or equal to {} is {}".format(n, count_primes))
輸出:
The number of prime numbers less than or equal to 150 is 35
相關用法
- Python next()用法及代碼示例
- Python os.dup()用法及代碼示例
- Python set()用法及代碼示例
- Python os.abort()用法及代碼示例
- Python os.WEXITSTATUS()用法及代碼示例
- Python os.fchmod()用法及代碼示例
- Python PIL getpixel()用法及代碼示例
- Python PIL putpixel()用法及代碼示例
- Python os.sysconf()用法及代碼示例
- Python os.confstr()用法及代碼示例
- Python os._exit()用法及代碼示例
- Python cmath.log()用法及代碼示例
- Python Tensorflow cos()用法及代碼示例
- Python sympy.rf()用法及代碼示例
注:本文由純淨天空篩選整理自rupesh_rao大神的英文原創作品 Python | sympy.primepi() method。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。