在simpy模塊中,我們可以測試給定數字n是否為質數sympy.isprime()
函數。對於n
請注意,負數(例如-13)不被視為素數。
用法: sympy.isprime() 參數: n; number to be tested 返回: bool value result
代碼1:
# Python program to check prime number
# using sympy.isprime() method
# importing sympy module
from sympy import *
# calling isprime function on differnet numbers
isprime(30)
isprime(13)
isprime(2)
輸出:
False True True
代碼2:
# Python program to check prime number
# using sympy.isprime() method
# importing sympy module
import sympy.ntheory as nt
# calling isprime function on differnet numbers
nt.isprime(30)
nt.isprime(13)
nt.isprime(2)
輸出:
False True True
相關用法
- Python os.dup()用法及代碼示例
- Python next()用法及代碼示例
- Python set()用法及代碼示例
- Python object()用法及代碼示例
- Python bytes()用法及代碼示例
- Python os.times()用法及代碼示例
- Python os.chmod用法及代碼示例
- Python hash()用法及代碼示例
- Python os.ftruncate()用法及代碼示例
- Python os.truncate()用法及代碼示例
- Python os.fsdecode()用法及代碼示例
- Python dict pop()用法及代碼示例
- Python os.abort()用法及代碼示例
- Python os.WEXITSTATUS()用法及代碼示例
注:本文由純淨天空篩選整理自Shivam_k大神的英文原創作品 Python | sympy.isprime() method。非經特殊聲明,原始代碼版權歸原作者所有,本譯文未經允許或授權,請勿轉載或複製。