Resolved: Why is the reverse method not working in question 2?
This is the code I'm using:
"inp=input('Please name your favorite food:>')
for n in (inp):
and here is the output i'm getting:
Thank you for your question!
Notice that, in your code, the
for-loop. Therefore, each time you append a letter to
lis, the program prints out the output of
lis.reverse. Since the word 'steak' contains 5 letters, the message is printed out 5 times. Additionally, what you print out is not the reversed list but rather a message describing what the
reverse() method is - namely, a built-in method of a list object.
What I provide below is a modification of the code, such that it returns a string with the reversed name of the food. Notice that on line 10 the
reverse keyword is followed by a set of parentheses.
Hope this helps!