def solution(words: str) -> int:
return sum([ord(i) for i in words])
assert solution("a") == 97
assert solution("aaa") == 291
assert solution("Mary had a little lamb") == 2001
def solution(words: str) -> int:
# your code
return sum(ord(i) for i in words)
assert solution("a") == 97
assert solution("aaa") == 291
assert solution("Mary had a little lamb") == 2001
def solution_3(a:str):
numic=0
for i in a:
numic+=ord(i)
return numic
# print(solution_3('Mary had a little lamb'))
assert solution_3("a") == 97
assert solution_3("aaa") == 291
assert solution_3("Mary had a little lamb") == 2001
def solution(words: str) -> int:
sum = 0
for i in words:
sum += ord(i)
return sum
assert solution("a") == 97
assert solution("aaa") == 291
assert solution("Mary had a little lamb") == 2001
def solution(words: str) -> int:
return sum(ord(i) for i in words)
assert solution("a") == 97
assert solution("aaa") == 291
assert solution("Mary had a little lamb") == 2001
def solution(words: str) -> int:
# ord:对字符串转换为ASCII值
result = [ord(i) for i in words]
# sum:返回所有字符对应的ASCII码数值的总和
return sum(result)
assert solution("a") == 97
assert solution("aaa") == 291
assert solution("Mary had a little lamb") == 2001
def solution(words: str) -> int:
return sum(ord(i) for i in words)
assert solution("a") == 97
assert solution("aaa") == 291
assert solution("Mary had a little lamb") == 2001