+ 1
How to print the previous alphabets of a given string?
Eg. If the Input is 'CAT’ the output will be 'BZS'. DOG-> CNF
7 Antworten
+ 8
A bit late, but i still want to share this code with you:
- the "replacement / movement" can be done in any direction by using positive or negativ numbers
- from module string the uppercase letters are used. this does not create an overhead, it just creates a variable with the alphabet
- the alphabet is used and rotated by the value of "move"
- a dictionary is created by using zip() with original alphabet and the rotated version
- the replacement is done in a list comprehension
*** this code can also be used to encrypt / decrypt text. in this case a shuffeld alphabet can be used instead of an ordered alphabet
https://code.sololearn.com/c1rNe8FqRU87/?ref=app
+ 4
this works with both small and capital letters..
a="CAT"
b=""
for i in a:
b += chr(ord(i)+25) if(i=='A' or i=='a') else chr(ord(i)-1)
print(b)
+ 3
a="CAT"
b=""
for i in a:
if ord(i)==65:
b+=chr(90)
continue
b+=chr(ord(i)-1)
print(b)
+ 3
Thank you guys.got it
+ 2
Another way will be to put the alphabet in a list or array and choose a previous index to the character input.
+ 1
I'm kind of a beginner so I didn't quite get Vitaly's code. I'm going with this
https://code.sololearn.com/c83qYy6QnfOh/?ref=app