对于此代码,我尝试将与 ASCII 中字符串的字母相对应的数字代码相加,然后返回数字,但是错误是
ord() expected a character, but string of length 8 found
但我以为我已经拆分了字符串以避免这种情况
这是不起作用的代码:
def checksum(string):
words = string.split()
for i in words:
num = ord(i)[0] + ord(i)[1:]
return num
例如,如果字符串是“hi”,那么输出应该是 301