0
你能幫我寫一個函數,它接收一個字符字符(即,一個無限長度的字符串)和整數旋轉。我的函數應該返回一個無限長度的新字符串,由旋轉的位置向右旋轉的結果。我對這段代碼的輸出應該是這樣的:函數接收和旋轉文本
Type a message:
Hey, you!
Rotate by:
5
Mjd, dtz!
到目前爲止,這是我:
def rotate_character(char, rot):
move = 97 if char.islower() else 65
return chr((ord(char) + rot - move) % 26 + move)
char = input('Type a message: ')
rot = int(input('Rotate by: '))
print(rotate_character(char, rot))
,這是錯誤消息我得到:
TypeError: ord() expected a character, but string of length 9 found on line 3