How to count number of rotation after rotating a string

Hello, comunity!

I wrote the below code to rotate a word

def rotation(s):
    b = len(s)
    for i in range (b):
        c = s[i:]+s[:i]
        print (c)

rotate (academic)



however I would like the output to be

Rotated 1 time = academic
Rotated 2 time = cademica
Rotated 3 time = ademicac
Rotated 4 time = emicacad

I know that I have to include in the

def rotation(s):
    b = len(s)
    for i in range (b):
        c = s[i:]+s[:i]
        print ("Rotated"+ " "+ n+"time="+c)

how do I get n?

thank you
1 Like

Maybe you could initialise a value of 1 for n within the for loop, initially. And increment it by 1 as long the strings keeps getting modified.

Hi @paolagarcia0815,

If you feel that  your question was successfully solved, could you please mark the helpful answer as Solution? You can find here how to do it technically (in the GUIDELINE #5). Please consider this practice also for any other questions you might ask in the Community. This would be of great help both to your helpers and the other learners who can have the same questions in the future.

Many thanks and happy learning! 

:rotating_light: NOTE: This is an automated message. Please do not reply. :rotating_light:

One way of doing this would be to replace n with i+1 (since i starts at 0)

this should work

for i in range (b):
     c = s[i:]+s[:i]
     print ("Rotated"+ " "+ str(i+1)+" time="+c)
1 Like