Question: 1. Write a function encipher(s, n) that takes as inputs an arbitrary string s and a non-negative integer n between 0 and 25, and that
1.
Write a function encipher(s, n) that takes as inputs an arbitrary string s and a non-negative integer n between 0 and 25, and that returns a new string in which the letters in shave been rotated by n characters forward in the alphabet, wrapping around as needed. For example:
>>> encipher('hello', 1) 'ifmmp' >>> encipher('hello', 2) 'jgnnq' >>> encipher('hello', 4) 'lipps' 2.
Write a function decipher(s) that takes as input an arbitrary string s that has already been enciphered by having its characters rotated by some amount (possibly 0). decipher should return, to the best of its ability, the original English string, which will be some rotation (possibly 0) of the input string s. For example:
>>> decipher('Bzdrzq bhogdq? H oqdedq Bzdrzq rzkzc.') 'Caesar cipher? I prefer Caesar salad.' 3.
Write a function abs_list_lc(values) that takes as input a list of numbers called values, and that uses a list comprehension to create and return a list containing the absolute values of the numbers in values. For example:
>>> abs_list_lc([-2, 5, 8, -3]) [2, 5, 8, 3]
4.
Write a function abs_list_rec(values) that takes as input a list of numbers called values, and that uses recursion to create and return a list containing the absolute values of the numbers in values. In other words, this function will do the same thing as the previous function, but it must use recursion instead of a list comprehension. For example:
>>> abs_list_rec([-2, 5, 8, -3]) [2, 5, 8, 3]
5.
Write a function called num_greater(threshold, values) that takes as inputs a number threshold and a list of numbers values, and that returns the number of elements of values that are greater than threshold. For example:
>>> num_greater(5, [1, 7, 3, 5, 10]) # there are 2 values > 5 2 >>> num_greater(2, [1, 7, 3, 5, 10]) # there are 4 values > 2 4 >>> num_greater(10, [1, 7, 3, 5, 10]) # there are 0 values > 10 0
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
