I am doing this python problem where I have to get a word input from the user and then flip the word backwards and print the letters out backwards, adding a letter each time. I've made it so I can flip the word backwards. I know I can use the
for c in word
statement but I'm unsure how to make it so I can add a letter each time.
Below are the instructions and my code.
The childrens' song Bingo is from 1780!
In the song, each verse spells the name "Bingo", removing one letter from the name each time.
When writing this program, you'll need to work out a few things:
You need a way to reverse the dog's name. You need a loop to build up the dog's name letter by letter. Each time you go through the loop you add another letter to the reversed name.
An example:
Name: bingo o
og
ogn
ogni
ognib
And ognib was their name-o
Code I have:
name = input("Name: ")
reversed_text = ''
last_index = len(name) - 1
for i in range(last_index, -1, -1):
reversed_text += name[i]
print(reversed_text)
Thanks