End of Summer - hours only!Up to 80% off on all courses and bundles.-Close
Cipher
7. Decode the word

Instruction

Great! Here's the last exercise.

Exercise

Write a function called decode() which has three arguments: word (the ciphered word), letter (the one unciphered letter from this word), letter_index (the index of this unciphered letter in this word). The function should return the whole unciphered word.

Here's an example:

decode('Atpgc', 'n', 4)
>> Learn

Here's a reminder of what the cipher() function looks like.

def cipher(word, shift):
  result = '' 
  for letter in word:
    if letter.isupper():
      result += chr((ord(letter) + shift - ord('A')) % 26 + ord('A'))
    else: 
      result += chr((ord(letter) + shift - ord('a')) % 26 + ord('a'))
  return result

Stuck? Here's a hint!

Use the given letter and the letter index to find out what the shift is.

shift = ord(letter) - ord(word[letter_index])

Then use the shift to decipher the whole word.