Вот мой код:Что такое IndexError? Я продолжаю получать его
quote = input("Enter a Sentence: ")
a = len(quote)
counter = 0
counter1 = 0
reverse = a
print("The Length of the sentence is",a,"characters long!")
for x in range(0,a):
if str.isspace(quote[x]) == True:
counter = counter + 1
print("The Length of the sentence is",a - counter,"characters long (excluding space...)!")
for x in range(0,a):
if str.isupper(quote[x]) == True:
counter1 = counter1 + 1
print("The number of Upper Case Characters in the sentence is",counter1,"characters!")
print("The number of Lower Case Characters in the sentence is",a-counter1,"characters long!\n")
while reverse >= 1:
r = reverse
print(quote[r])
r = r - 1
цель это, чтобы найти все об этом предложении, но единственная проблема является «В то время как» петля в нижней части. Кажется, что это не работает, и цель состоит в том, чтобы «отменить» предложение. Тем не менее, это дает мою ошибку, которая выглядит примерно так:
Traceback (most recent call last):
File "C:\Documents and Settings\ususer\My Documents\Downloads\StringStuff.py", line 27, in <module>
print(quote[r])
IndexError: string index out of range
Что я делаю неправильно? Пожалуйста помоги!
использовать 'print (r)', чтобы обнаружить вашу проблему – mrKelley