Question: PYTEST: def test_simpleEncode_1 (): assert simpleEncode('beep beep boop', createAlphabet(), createCipher(createAlphabet())) == '~,,Qf~,,Qf~RRQ' def test_simpleEncode_2 (): assert simpleEncode('only these characters have to be in alphabet', 'pq',
PYTEST:
def test_simpleEncode_1(): assert simpleEncode('beep beep boop', createAlphabet(), createCipher(createAlphabet())) == '~,,Qf~,,Qf~RRQ' def test_simpleEncode_2(): assert simpleEncode('only these characters have to be in alphabet', 'pq', 'st' ) == None def test_simpleEncode_3(): assert simpleEncode('only these characters have to be in alphabet', 'onlythescarvbip ', 'pasdfghjklzxcvbn' ) == 'pasdnfghjhnkglzlkfhzjnglxhnfpnchnvanlsbglchf' def test_simpleEncode_4(): assert simpleEncode('thisIsMyPlainText', 'someAlphabet','wrongLength') == -1

Is there any way to rewrite the cipher.index part?
We have not learn this function yet.
we only learned variable[i]
def simpleEncode (plaintext, alphabet, cipher): Given plaintext to encode, an alphabet and a cipher, return the encoded ciphertext. If the lengths of the alphabet and cipher are not the same, return -1. If a character from plaintext is not found in the alphabet, return None. ## ## # # ## ## if len(alphabet) !=len (cipher): return -1 ciphertext = "" for char in plaintext: if char not in alphabet: return None for i in range (0, len (alphabet)): if char == alphabet[i]: return ciphertext if len (alphabet) != len(cipher): return -1 for char in plaintext: if char not in alphabet: return None ciphertext = " for char in plaintext: ciphertext += cipher (alphabet.index (char)] return ciphertext
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
