I'm stuck in solving the following exercise:
"*From the standard input you will get an integer n and a message encrypted by Caesar cipher (i.e. shifted by n letters down the alphabet). Decrypt the message and print it.
Hint: Functions chr a ord, function print with parameter end=''.
Try Also:
-3#Jrf rf rnxz*"
**Sample Input:
5#Rfrf rjqj rfxt**
**Sample Output:
Mama mele maso**
The code I've wrote is the following:
posun, zprava = input().split("#")
for i in zprava:
a = ord(i) - int(posun)
print(chr(a), end='')
But except for having the requested output, the exercise is tagged as wrong. Any suggestion?
gog
11.4k2 gold badges29 silver badges42 bronze badges
lang-py
print()at the end to flush stdout.ord(' ')?ord("a") - 1you want to end up inz, but in the ascii table the character beforeais not z. You will need some code to check that your value keep in the range a-z. Similarly, if you use negative Cesar offsets, then you might end up with characters "above"z, so you want also to consider cases likeord("z") + 1. In addition your code also uses capital letters, so you have two ranges to consider: a-z and A-Zif i in string.ascii_lowercase or string.ascii_uppercaseis not doing an or the way you think, you should instead doif i in string.ascii_lowercase or i in string.ascii_uppercaseyou could start with checking how the syntax for boolean operations work.