获取IndexError: python中的字符串索引超出范围,我是python的初学者并试图制作一个程序来计算大写和小写字母的总数,我还尝试了一些解决方案,如删除字符串的空格,string.replace(" ", "")但再次出错,
我的代码
string = input('Enter string upto 25 words: ')
if len(string) > 25:
print('Please enter a string less than 25 words.')
else:
string.replace(" ", "")
total_upr = 0
total_lwr = 0
i = 0
while i < 25:
print(i)
if string[i].islower():
total_upr += 1
elif string[i].isupper():
total_lwr += 1
i += 1
print(f"'{string}' contains {total_lwr} lower-case letters and {total_upr} upper-case letters.")
FFIVE
翻阅古今
牧羊人nacy
相关分类