-
-
Notifications
You must be signed in to change notification settings - Fork 44.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add emirp number detection algorithm #11361
base: master
Are you sure you want to change the base?
Conversation
Add emirp number detection algorithm
Replaced`for` loop in `is_prime` function with a generator expression.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Can we do something like this?
"""
Check if a number is an emirp number.
Args:
number: A positive integer.
Returns:
True if the number is an emirp number, False otherwise.
Raises:
ValueError: If number is not a positive integer.
Examples:
>>> emirp_check(13)
True
>>> emirp_check(23)
False
>>> emirp_check(9679)
True
>>> emirp_check(5)
False
>>> emirp_check(0)
Traceback (most recent call last):
...
ValueError: Input must be a positive integer.
>>> emirp_check(-13)
Traceback (most recent call last):
...
ValueError: Input must be a positive integer.
>>> emirp_check(1.9)
Traceback (most recent call last):
...
ValueError: Input must be a positive integer.
>>> emirp_check("cat")
Traceback (most recent call last):
...
ValueError: Input must be a positive integer.
>>> emirp_check(17)
True
>>> emirp_check(31)
True
>>> emirp_check(79)
False
>>> emirp_check(101)
False
"""
We can do it this way as well. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great!!
Describe your change:
Add emirp number detection algorithm.
Implemented functions
is_prime
andemirp_check
to determine whether a given number is an emirp number. An emirp number is a prime number that yields a different prime number when its digits are reversed.Checklist: