Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Write function rot13 - it takes a message as a parameter, and it returns an encr

ID: 3831654 • Letter: W

Question

Write function rot13 - it takes a message as a parameter, and it returns an encrypted string in which all the characters in the message are rotated by 13 places. You may assume that all characters in the message are lower case letters (no upper case letters, spaces, digits or anything else). Here is a skeleton of the function. We have initialized an important variable, and given in-line comments to help you out. def rot13(message): result = "" # starts empty; add one character at a time below # loop through each character # shift it by 13 places (may wrap around to front of alphabet) # add it to the result string Of course you should return the result at the end too.

Explanation / Answer

def rot13(message):
   result = ""
   for s in message:
       n = ord(s)-ord('a')
       n = (n+13)%26
       n = n+ord('a')
       result+=chr(n)
   return result
print(rot13("abcdxyz"))

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote