0

I've made a reverse function, it reverses the sentence, however it generates index error.

what the program does is append the last word from s and puts it into rev[], it then deletes the word s[-1].

s = "This is awesome"

def Reverse1(s):

s = s.split(" ") #reverses the word instead of letters
rev = []                    
while True:
    rev.append (s[-1])
    del s[-1]
    print (rev)
return  
reverse1(s)

its returning index error as it tries to continue when s is empty so I think its the while loop statement.

any ideas?

1 Answer 1

1

You need to stop the while loop, you can use something like this

while n in range(len(s)):
Sign up to request clarification or add additional context in comments.

2 Comments

Thanks mate much appreciated
Give me positive rating! i need it to get unblocked, Thanks.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.