from string import lowercase
# print lowercase
a = raw_input("Enter a string:")
a_lower = a.lower()
# print a_lower
def alpha_sum(s):
total=0
for i in s:
if i in lowercase:
total += (lowercase.index(i)+1)
else:
pass
return total
print alpha_sum(a_lower)python计算一段字符串字母的和(a,b分别为1,2)
最新推荐文章于 2022-08-18 21:34:15 发布
本文介绍了一个简单的Python程序,该程序接收用户输入的一串字符,并将其转换为小写形式。接着定义了一个函数用于计算字符串中小写字母的总分,其中每个字母的分数为其在字母表中的位置。通过这个例子,读者可以学习到如何使用Python进行基本的字符串操作及遍历计算。
6461

被折叠的 条评论
为什么被折叠?



