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".
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"
Lessons in this chapter · Python Coding Quiz Practice
- 1. Coding Quiz - Palindrome Check
- 2. Checking for Palindrome Strings - Problem Solving
- 3. Coding Quiz - Find Unique Words
- 4. Finding Unique Words - Problem Solving
- 5. Coding Quiz - Caesar Cipher
- 6. Caesar Cipher - Problem Solving
- 7. Coding Quiz - Find Prime Numbers
- 8. Finding Primes - Problem Solving
- 9. Coding Quiz - Finding Indices for a Target Sum
- 10. Creating Target Value with Two-Sum - Problem Solution
- 11. Coding Quiz - Maximize Stock Trading Profit
- 12. Finding Maximum Profit - Solution Explanation
- 13. Coding Quiz - Detecting Anagrams
- 14. Anagram Checker - Problem Solution
- 15. Coding Quiz - Remove the Smallest Number
- 16. Removing the Smallest Number - Problem Solution
Lecture
AI Tutor
Design
Upload
Notes
Favorites
Help