Write a function called
rotate_word()that takes a string and an integer as parameters, and returns a new string that contains the letters from the original string rotated by the given amount.Rotate_word('cheer',7) == 'jolly',Rotate_word('melon', -10) = 'cubed',**
My Python code is:
def Rotate_word(str_, num_):
result = ''
for i in str_:
i = chr(ord(i) + num_)
result = result + i
return (result)
str_ =input("Enter a string: ")
num_ = int(input("Enter rotate number: "))
print (Rotate_word(str_,num_))
It gives output like:
Enter a string: cheer
Enter rotate number: 7
jolly
Which is correct.
Enter a string: melon
Enter rotate number: -10
c[bed
This is wrong the correct answer is cubed
What am I doing wrong and how can I fix it?