(Using Python)Part 2a Numerology is the \"study of the purported mystical or spe
ID: 3760126 • Letter: #
Question
(Using Python)Part 2a
Numerology is the "study of the purported mystical or special relationship between a number and observed or perceived events." It has been used throughout human history as a way to attach meaning to a name, object or event using mathematics. It is considered a "pseudoscience" by modern scientists since it has no basis in observable phenomena. With that said, it makes a great programming challenge so we're going to go with it! :)
What you want to do for this project is to ask the user to type in their name. Next, you will need to use a technique called "theosophical reduction" to convert their name into a number. With this technique we assign each letter of the alphabet its own number. For example, the letter "a" is equal to the number 1. "b" = 2, "c" = 3, "z" = 26, etc. You should ignore non-alphabetic characters (i.e. numbers, spaces and special characters)
Once you've gotten all of the letters converted into numbers you can add them up into one single number. This is the "numerology number" for the name that the user entered.
So for the name "craig" the numerology number would be:
Here's are a few sample runnings of this program:
Some hints:
Convert the user's name to all uppercase or all lowercase before you do anything else
Remove any spaces, numbers or special characters from the name to ensure that you are only working with the letters A-Z
The ord() function may be userful to convert each character into an ASCII index
Explanation / Answer
Solution for above python problem is below..
import re
s = "abc" # enter string here
#s = "hello world! HELLOW INDIA how are you? 01234"
# Short version
print filter(lambda c: c.isalpha(), s)
# Faster version for long ASCII strings:
id_tab = "".join(map(chr, xrange(256)))
tostrip = "".join(c for c in id_tab if c.isalpha())
print s.translate(id_tab, tostrip)
# Using regular expressions
s1 = re.sub("[^A-Za-z]", "", s)
s2 = s1.lower()
print s2
import string
values = dict()
for index, letter in enumerate(string.ascii_lowercase):
values[letter] = index + 1
sum = 0
for ch2 in s2:
for ch1 in values:
if(ch2 == ch1):
sum = sum + values[ch1]
print sum
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.