A number and a word are provided. For example:
value = 3
word = 'NAME'
I have to loop through the word NAME
and remove one letter at a time and finally display the last letter remaining. The pattern of removal is: starting from the first letter, advance through value
letters in a cycle (once reach the end, start from index 0) and remove the reached letter.
For example, if the value is 3
. It would count 3
starting at N
and remove first M
.
Remaining is NAE
- count to 3
from the next letter which is now E
, then A
will be removed.
Remaining is NE
- count to 3
, starting from E
then E
will be removed and only N
remains. The result will be shown N
. I am not able to find a way to construct a loop to do this iteration.
As of now I’ve done manually and made it like
if value == 4:
print('A')
elif value == 1:
print('E')
elif value ==2:
print('N')
This is not practical since the value would be anything between 1-100
. Any other solution by which this will automatically iterate and remove and show me the final letter.