Last active
July 23, 2020 18:51
-
-
Save orjanv/659d4fcd0940153ea13e4b6a0401f258 to your computer and use it in GitHub Desktop.
Convert each character in a name to a number (a=1, b=2..) and check if it is a prime number summed.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python3 | |
# coding: utf-8 | |
def main(): | |
'''Convert each character in a name to a number (a=1, b=2..) | |
and check if it is a prime number summed.''' | |
chars = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', \ | |
'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', 'æ', 'ø', 'å'] | |
# Get a name input, can be one or more names | |
input_name = input('Enter a name: ') | |
# Check each character againts the alphabet list, and sum it | |
sum_name = (sum(chars.index(c) + 1 for c in input_name.lower().replace(" ", "").replace("-", ""))) | |
# Check if the sum is a prime number or not | |
if all(sum_name % i for i in range(2, sum_name)): | |
print("{} is prime ({})".format(input_name, str(sum_name))) | |
else: | |
print("Sorry, {} is not prime".format(input_name)) | |
if __name__ == '__main__': | |
main() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment