DEV Community

Cover image for Name to Number Converter
Scott Gordon
Scott Gordon

Posted on

Name to Number Converter

# name_to_number_converter.py
#   This program calculates the numeric value of a single name based on
#   the provided input and the assigned letter values. a=1, b=2, c=3 ...
# by: Scott Gordon

# Print welcome message
print("***** Welcome to The Name to Number Converter *****")

# Get user input and assign it to the name variable and convert to lowercase
name = input("What is the name you would like to calculate? ")
name = name.lower()

# Create a lookup table of the alphabet.
alphabet = "abcdefghijklmnopqrstuvwxyz"

# Iterate through each letter in the name variable
sum = 0
for letter in name:
    # TODO Each pass add the index number from the lookup table to the variable sum.
    sum += (alphabet.index(letter)+1)

# Print the value of the name to the end user.
print(f"The value of the name you entered is {sum}.")
Enter fullscreen mode Exit fullscreen mode

Photo by Jon Tyson on Unsplash

Top comments (0)