Converting String to Ordinal Value

前端 未结 2 1469
误落风尘
误落风尘 2021-01-29 14:17

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.



        
2条回答
  •  死守一世寂寞
    2021-01-29 14:47

    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
    

提交回复
热议问题