CPSC120
Fundamentals of Computer Science

In-class Activity 15

  1. Is Alphabetic

    Create a function called is_alphabetic(character) that returns True if the specified character is an alphabetic character (a - z or A - Z) and False otherwise. Use the built in function ord to determine if a character is alphabetic. Do not use any string methods.

  2. String Strip

    Create a function called strip_non_alpha(text) that returns a new string that is the same as the specified string with all characters that are not alphabetic removed.

  3. rot13

    Create a function called rotate_thirteen(text) that returns a string that has been modified according to the rot13 encryption algorithm. The name rot13 is short for rotate thirteen. The algorithm rotates all alphabetic characters in a string by 13 places. That is, a letter is replaced with the letter that is 13th later in the alphabet. For example, the letter “A”, the first in the alphabet, would be replaced with the fourteenth letter in the alphabet, “N”. For letters in the second half of the alphabet, the alphabet is wrapped. For example the letter “Z”, the twenty sixth letter in the alphabet, would be replaced with the thirteenth letter in the alphabet, “M”. Characters that are not letters are removed and characters that are lowercase letters are converted to uppercase.