I want to rotate a word to the right, so that every letter has passed.
What I tried to do is make a function. It looks like this (yeah yeah ik lmao):
word = "Abobus";
length = len(word);
n = 1;
def rotation():
for i in range(length + 1):
c = word[0 : length-n] + word[length-n:]
print(c)
rotation();
I needed the output to be:
Abobus
sAbobu
usAbob
busAbo
obusAb
bobusA
Abobus
Instead, the output was:
Abobus
Abobus
Abobus
Abobus
Abobus
Abobus
Abobus
What exactly am I doing wrong?
>Solution :
You are splitting at an index in word, but then just putting the two pieces back together. Also, you are not use i to move the split index.
def rotation(word):
length = len(word)
for i in range(length):
c = word[-i:] + word[:-i]
print(c)
rotation('Abobus')
# prints:
Abobus
sAbobu
usAbob
busAbo
obusAb
bobusA