Numerologists claim to be able to determine a person's character traits based on the "numeric value" of a name. The value of a name is determined by summing up the values of the letters of the name, where "a" is 1 "b" is 2 "c" is 3 and so on up to "z" being 26. For example, the name "Python" would have the value 16 + 25 + 20 + 8 + 15 + 14 = 98. Write a program that calculates the numeric value of a name provided as input in python
Code
def name_value(name):
name = name.lower()
value = 0
for char in name:
value += ord(char) - 96
return value
if __name__ == "__main__":
name = input("Enter name: ")
print("Value of name: %d" % name_value(name))
Output
0 Comments
Post a Comment