We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent 50a1a9d commit 804b796Copy full SHA for 804b796
caesar-cipher-1.py
@@ -0,0 +1,30 @@
1
+# https://www.hackerrank.com/challenges/caesar-cipher-1
2
+# old logic, may be using DICT can improve the code.
3
+#!/bin/python3
4
+
5
+import sys
6
7
8
+n = int(input().strip())
9
+s = input().strip()
10
+k = int(input().strip())
11
+s = list(s)
12
+k = k%26
13
14
+for i in range(n):
15
+ if s[i].isalpha():
16
+ if s[i].islower():
17
+ if ord(s[i])+k > ord('z'):
18
+ s[i] = chr(ord('a')-1+k-ord('z')+ord(s[i]))
19
+ else:
20
+ s[i] = chr(ord(s[i])+k)
21
22
+ if ord(s[i])+k > ord('Z'):
23
+ s[i] = chr(ord('A')-1+k-ord('Z')+ord(s[i]))
24
25
26
+print(''.join(s))
27
28
29
30
0 commit comments