Lecture

Coding Quiz - Caesar Cipher

In this coding quiz, you will write a function to apply the Caesar cipher to a given string.

The Caesar cipher is a method of encrypting text by shifting each letter a specific number of places down the alphabet. For example, shifting 'a' by 3 results in 'd', and shifting 'z' by 2 results in 'b'.

The user provides a string and an integer 'shift' value, and you are to replace each letter in the string with a letter that's 'shift' positions later in the alphabet to return a new string.

For instance, if the 'shift' is 3 and the input string is "abc", the output string should be "def".


Write the code
def solution(text, shift): # Write your code here return



Constraints

  • The input string consists of only English letters, and it is case-sensitive.

  • Spaces, special characters, and numbers are not transformed.

  • The 'shift' value is an integer.




Example Input/Output

  • Input: string "abc", 'shift' 3

  • Output: "def"


  • Input: string "XYZ", 'shift' 2

  • Output: "ZAB"

Lecture

AI Tutor

Publish

Design

Upload

Notes

Favorites

Help