I have been assigned to create an application that takes a user's first and second name (making sure they're no longer than 10 characters) and calculate their 'lucky name number' based on this grid:
So for example, John Smith would be:
= (1 + 6 + 8 + 5) + (1 + 4 + 9 + 2 + 8)
= 20 + 24
Then add the digits in each value together:
= (2 + 0) + (2 + 4)
= 2 + 6
= 8 <- Their lucky name number.
Here is the code I have so far:
while True:
first_name = input("What is your first name? ")
if len(first_name) < 10:
print("Hello " + first_name + ", nice name!")
break
else:
print("First name is too long, please enter a shorter name.")
while True:
second_name = input("What is your second name? ")
if len(second_name) < 10:
print ("Wow, " + first_name + " " + second_name + " is a really cool name. Let's see how lucky you are...")
break
else:
print ("Second name is too long, please enter a shorter name.")
However, I am unsure what my next step would be as I need to take each letter in the name and make it a specific value.
The only way I can think of doing this is by listing each letter with its assigned value like this:
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
fletter_1 = first_name[0]
fletter_2 = first_name[1]
fletter_3 = first_name[2]
fletter_4 = first_name[3]
fletter_5 = first_name[4]
fletter_6 = first_name[5]
fletter_7 = first_name[6]
fletter_8 = first_name[7]
fletter_9 = first_name[8]
fletter_10 = first_name[9]
print fletter_1 + fletter_2 + fletter_3 + fletter_4 + fletter_5 + fletter_6 + fletter_7 + fletter_8 + fletter_9
But this is an extremely long process and not the best way to code.
Please can someone give me some guidance on how I would complete the next step in the best way possible as I am unsure on what to do.