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

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!