Skip to main content
Practice

coding-quiz-3

---
id: coding-quiz-3
title: Coding Quiz - Caesar Cipher
description: Write a function to apply the Caesar cipher to a string
tags:
- Coding Quiz
- String Manipulation
- Loops
- Python
- Practical
sidebar_position: 5
isPublic: false
---

# 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".

<br />

```python title="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"

Want to learn more?

Join CodeFriends Plus membership or enroll in a course to start your journey.