Converting String to Ordinal Value

ipconfig picture ipconfig · Apr 13, 2016 · Viewed 7.6k times · Source

I'm looking to compute the sum of the ordinal values of all the characters of the full name string, and will output this sum.

here is what I have so far.

a = input('Enter your first name: ')
b = input('Enter your last name: ')
c = print("your full name is:", a, b)
print(ord(a))

so for example if you put Mary for the first name and Joe for the last name the full name would be Mary Joe and the ordinal value would be 727.

Answer

AKS picture AKS · Apr 13, 2016

If you only concatenate a and b you will get 695:

print(sum(ord(i) for i in a+b))
# 695

But, it seems you also need a space between the first and last name:

print(sum(ord(i) for i in '{0} {1}'.format(a, b)))
# 727