15,942,710 members
1.00/5 (1 vote)
See more:
In Caesar cipher, each letter is replaced by another letter which occurs at the d-th position (when counted from the position of the original letter), in the English alphabet. For identifying the position of a letter, we follow the usual order of the English alphabet, from a to z. Given a word and a positive integer d, use Caesar cipher to encrypt it. For example, if the word is 'ball' and the value of 'd' is 3 then the new encrypted word is 'edoo'. 'x' will be replaced by 'a', 'y' should be replaced by 'b' and 'z' should be replaced by 'c'. While the code is submitted for Online Judge (SkillRack), use rstrip(), to remove carriage return character in the input.

Input Format

Word

A positive integer 'd'

Output format:

Encrypted word

What I have tried:

y=input()
l=[]
x=l.append(y)
d=int(input())
for i in range(0,len(y)):
x[i]=chr(ord(x[i])+3)
print(x)
Posted
Updated 12-Dec-20 6:15am

## Solution 1

We are more than willing to help those that are stuck: but that doesn't mean that we are here to do it all for you! We can't do all the work, you are either getting paid for this, or it's part of your grades and it wouldn't be at all fair for us to do it all for you.

So we need you to do the work, and we will help you when you get stuck. That doesn't mean we will give you a step by step solution you can hand in!
Start by explaining where you are at the moment, and what the next step in the process is. Then tell us what you have tried to get that next step working, and what happened when you did.

If you are having problems getting started at all, then this may help: How to Write Code to Solve a Problem, A Beginner's Guide[^]

## Solution 2

you could start by using meaningful names for your variables. Using single letters does not make your code more efficient, in fact quite the opposite, because it is more difficult t understand. So, following the instructions:
Python
```word = input("Enter the source word: ")
offset = int(input("Enter the offset value: "))

Now you can think about how you process each letter in the string. Remember to calculate the new value when the addition of the offset goes beyond the letter z (or Z). It is probably easiest to stick to all lower case or all upper case to start with.