Please ignore secret bonuses. Secret tests do NOT award bonus. Max hw grade is 30+2 bonus efficiency

Do you need help?

Notice Board

Per partecipare al corso di Fondamenti di programmazione 2023-24 loggatevi e attivatelo nella vostra pagina dei corsi preferiti. A quel punto il corso appare nel menù personale cliccando sul proprio avatar. Per i materiali degli anni precedenti seguite lo stesso metodo.

To join the Programming/Lab 2023-24 course, log-on and select it on the my courses page. It will appear on the personal menu of your avatar. For earlier years use the same method.

I don't think the Caesar Problem is doable with what we learned in class.

Beray Nil Atabey (7510 points)
13 33 97
in Programming in Python by (7.5k points)
closed by
So the Caesar Cipher problem (on replit) asks us to rotate each letter of the alphabet by 3, but we didn't learn anything that helps us link a normal alphabet with the rotated alphabet. If you solved it using what we learned in class, how did you approach this problem?

PROBLEM SOLVED → Prof. Mancini defined new functions and explained new concepts in class on 19.10.2022 to help us solve this problem.
550 views
closed with the note: solved

3 Answers

Cigo (5050 points)
3 6 48
by (5.1k points)

So:

  • You make a variable with the alphabet inside AND abc at the end (cause if you expand z by 3, you get c. If you don't do this, you'll get an IndexError later
  • You use a counter to track the index you are currently in and you start a for loop of the alphabet
  • Inside the loop you check if you character is equal to the one in the alphabet, and if yes you return the element in the index given by your counter + 3 (like alphabet[c + 3[ with c being the counter)
This is for the first one. The second one works exactly the same: for every letter of the string you want to encode, you just transorm it in its related moved-by-3 form and then return the new string.
Beray Nil Atabey (7510 points)
13 33 97
by (7.5k points)
edited by
Understood, thank you!
francesco.calzona (5210 points)
5 20 81
by (5.2k points)
I approached it by defining a string containing the whole alphabet; then, since the request is not to rotate the alphabet itself, but just a character or a string of character (whose procedure is just the one I am to explain with one character, repeated for each of them), I would first find the position, or index i, of the character in the alphabet (with the find function for example), and then create a new string with the character from the alphabet at the desired position i + the shift. [To avoid going out of range, just use shift%26, since every time after 26 letters the alphabet repeats again.] Note that we have to create a new string to do this procedure, and we cannot change the existing one, character by character, since strings are immutable and their characters cannot be changed.
mauman (1540 points)
52 77 83
by (1.5k points)
Hi,

I updated the exercise on repl.it, the link remains the same, so you can re-fork it and solve it based on what I covered in the last calss.