This shows you the differences between two versions of the page.
ii:labs:s2:01:tasks:01 [2023/03/18 18:00] florin.stancu |
ii:labs:s2:01:tasks:01 [2024/03/15 13:30] (current) florin.stancu [01. [20p] String manipulation] |
||
---|---|---|---|
Line 1: | Line 1: | ||
- | ==== 01. String manipulation ==== | + | ==== 01. [25p] String manipulation ==== |
First, let's familiarize ourselves with Python's string type: | First, let's familiarize ourselves with Python's string type: | ||
Line 6: | Line 6: | ||
* Print the reversed string (e.g., "hello world" => "dlrow olleh"); hint: there are at least 3 built-in ways to do this in a single line of code ;) | * Print the reversed string (e.g., "hello world" => "dlrow olleh"); hint: there are at least 3 built-in ways to do this in a single line of code ;) | ||
* Print the same string in "aLtErNaTe CaSe" (if you're out of ideas, simply use the [[https://docs.python.org/3/tutorial/controlflow.html#for-statements|for loop]]); | * Print the same string in "aLtErNaTe CaSe" (if you're out of ideas, simply use the [[https://docs.python.org/3/tutorial/controlflow.html#for-statements|for loop]]); | ||
- | * Finally: encrypt the given message using [[|Caesar's Cipher]] (aka, shift each of its alphabet letters to ''n'' positions to the: right for encryption, left for decryption); use the number ''17''' for testing! | + | * Finally: encrypt the given message using [[https://en.wikipedia.org/wiki/Caesar_cipher|Caesar's Cipher]] (aka, shift each of its alphabet letters to ''n'' positions to the: right for encryption, left for decryption); use the number ''17''' for testing! |
<note> | <note> | ||
Line 13: | Line 13: | ||
* You can use the ''[[https://docs.python.org/3/library/functions.html#ord|ord()]]'' built-in function to get the ASCII code of a character (as ''int''); | * You can use the ''[[https://docs.python.org/3/library/functions.html#ord|ord()]]'' built-in function to get the ASCII code of a character (as ''int''); | ||
* For the reverse process (''int'' to ''str'' character) you have ''[[https://docs.python.org/3/library/functions.html#chr|chr()]]''; | * For the reverse process (''int'' to ''str'' character) you have ''[[https://docs.python.org/3/library/functions.html#chr|chr()]]''; | ||
- | * Don't forget to wrap around when you reach the last letter of the alphabet! E.g., ''Z + 1 => A''. | + | * Don't forget to wrap around when you reach the last letter of the alphabet: ''Z + 1 => A''! |
</note> | </note> | ||