Timeline for Caesar cipher in Python, exercise
Current License: CC BY-SA 4.0
11 events
| when toggle format | what | by | license | comment | |
|---|---|---|---|---|---|
| Oct 10, 2022 at 9:39 | comment | added | user2261062 |
you should update your question with your code, not write a comment. I'd recommend you take a look at a python tutorial to get familiarized with the language, and maybe start with an easier exercise if this one is giving you problems. if i in string.ascii_lowercase or string.ascii_uppercase is not doing an or the way you think, you should instead do if i in string.ascii_lowercase or i in string.ascii_uppercase you could start with checking how the syntax for boolean operations work.
|
|
| Oct 10, 2022 at 9:21 | comment | added | Disobey1991 | @SembeiNorimaki I've tried to define something like: for i in zprava: if i in string.ascii_lowercase or string.ascii_uppercase: if ord(i) in range(65, 91) or range(97, 123): a = ord(i) - int(posun) print(chr(a), end='') and I'm receiving as an output what I need, but is still giving me error in exercise | |
| Oct 10, 2022 at 9:02 | comment | added | bereal |
Caesar cipher usually assumes that a-1 = z etc, so you may want to try some modular arithmetic.
|
|
| Oct 10, 2022 at 9:01 | comment | added | mousetail |
Your code will fail if there is more than 1 # sign
|
|
| Oct 10, 2022 at 8:59 | comment | added | user2261062 |
Yes, if you do ord("a") - 1 you want to end up in z, but in the ascii table the character before a is 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 like ord("z") + 1. In addition your code also uses capital letters, so you have two ranges to consider: a-z and A-Z
|
|
| Oct 10, 2022 at 8:59 | history | edited | gog | CC BY-SA 4.0 |
added 47 characters in body
|
| Oct 10, 2022 at 8:56 | comment | added | Disobey1991 | @SembeiNorimaki subtracting 5 to ord('b') is giving me 93 as a result; Jiří Baum, in your case is giving 27. But I don't understand what you mean. The problem is that I'm going out of the range of the alphabet? | |
| Oct 10, 2022 at 8:42 | comment | added | Jiří Baum |
In addition, to what @SembeiNorimaki wrote, what happens if you subtract 5 from ord(' ')?
|
|
| Oct 10, 2022 at 8:41 | comment | added | user2261062 | if you substract 5 from ord('f') you end up with ord('a') -> good. But think what happens if you substract 5 from ord('b')? you have to keep in the a-z or A-Z range. | |
| Oct 10, 2022 at 8:41 | comment | added | Aran-Fey |
Try adding print() at the end to flush stdout.
|
|
| Oct 10, 2022 at 8:38 | history | asked | Disobey1991 | CC BY-SA 4.0 |