
取出字符串的每一个字符求ASCII码并求和
输入输出示例| 输入 | 输出 | |
| 示例 1 | Hello World! | The sum for string 'Hello World!' is 1085 |
s = input('Enter a String: ')
total = 0
for c in s:
total = total + ord(c)
print("The sum for string '" + s + "' is " + str(total))
# 方案2
def method2():
s = input('请输入一串字符:')
if s == ''.join(reversed(s)):
print(s, '是回文')
else:
print(s, '不是回文')
method2()