Reputation: 1
So I have a dictionary:
a_dict = {
"a": 1,
"b": 2,
"c": 3,
"d": 4,
"e": 5,
"f": 6,
"g": 7,
"h": 8,
"i": 9,
"j": 1,
"k": 2,
"l": 3,
"m": 4,
"n": 5,
"o": 6,
"p": 7,
"q": 8,
"r": 9,
"s": 1,
"t": 2,
"u": 3,
"v": 4,
"w": 5,
"x": 6,
"y": 7,
"z": 8
}
This is for a cipher called the numerology cipher. Each number in a name is assigned to 1-9 repeating. So 'a' is 1, 'b' is 2, and so on.
I have a name catcher as such:
print("Please type the name:")
name = input()
length_word = len(name)
list= list(name)
print(list, length)
# ['h','e','l','l', 'o']
The next part is where I'm lost. I'm trying to pass in the name variable into some function with my dictionary so I can select the value for my cipher.
#This is my paltry attempt.
#Try 1
letter_storage = []
#Try 2
#def spin(a_dict,list):
# for char in name:
# if char in a_dict:
# print(char)
letter_storage.append(guess)
if guess in name:
print("You guessed correctly!")
for x in range(0, length_word): #This Part I just don't get it
if secretWord[x] == guess:
guess_word[x] = guess
print(guess_word)
#Try 3
#print(a_dict, list)
#if letter in a_dict:
# print(letter),
#else:
#print("There are no letters:" , letters)
#return
There are several different attempts (including a "hangman" chop) ,but each failed its job to capture a name, and pass it to the dictionary for reference.
After this, I just need to add up the corresponding numbers in the value section all together into one large sum of both the first and last names.
Any help would be appreciated! Thank you!
Upvotes: 0
Views: 67
Reputation: 3711
a_dict = {
"a": 1,
"b": 2,
"c": 3,
"d": 4,
"e": 5,
"f": 6,
"g": 7,
"h": 8,
"i": 9,
"j": 1,
"k": 2,
"l": 3,
"m": 4,
"n": 5,
"o": 6,
"p": 7,
"q": 8,
"r": 9,
"s": 1,
"t": 2,
"u": 3,
"v": 4,
"w": 5,
"x": 6,
"y": 7,
"z": 8
}
print("Please type the name:")
name = input()
total = 0
for letter in name:
total += a_dict[letter]
print(total)
Upvotes: -1
Reputation: 71454
Here's a simple function that takes a string and a cipher dictionary and uses the dictionary to translate the string:
def encipher(message: str, cipher: dict) -> str:
"""Substitute each letter of the message using the cipher dict."""
return ''.join(
str(cipher[char])
for char in message
)
name = input("Please type the name: ")
print(f"Good to meet you, {encipher(name, a_dict)}!")
Upvotes: 2