Question
import string def createAlphabet(): createAlphabet returns a string that includes all lowercase letters, followed by all upper-case letters, then a space, a comma, a
import string def createAlphabet(): """ createAlphabet returns a string that includes all lowercase letters, followed by all upper-case letters, then a space, a comma, a period, a hyphen('-'), a tilde('~'), and a pound symbol ('#'). NOTE: the order of characters in the alphabet is very important! In other words, the string being returned will be 'abcdef...xyzABCDEF...XYZ ,.-~#' (the ellipses ... hide the alphabet letters) """ lc = string.ascii_lowercase uc = string.ascii_uppercase return lc + uc + " ,.-~#"
def getCharacterForward(char, key): """ Given a character char, and an integer key, the function shifts char forward `key` steps. Return the new character. If `char` is not a single character, return `None`. If `key` is not an integer, return -1. """ # If `char` is not a single character, return `None`. if len(char) != 1: return None # If `key` is not an integer, return -1. if type(key) != int: return -1 all_chars = createAlphabet() index_of_char = all_chars.index(char) # is there any way to rewrite this part? We have never learn all_chars.index() function, It is fine to be more complicated index_of_result_char = (index_of_char + key + len(all_chars)) % len(all_chars) return all_chars[index_of_result_char]
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started