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.

Problem with à in HW4_rec

z
zaur (740 points)
3 6 8
in HW4 by (740 points)
edited by
In one of the tests of the hw4 recovery, print_recorded_exams function, italian letter à breaks the code.  Apparently, len function considers this letter as 2 which causes issue while printing. Using encoding utf-8 i could fix its appearance in the file. However, while running it gives this error: UnicodeDecodeError: 'utf-8' codec can't decode byte 0xe0 in position 1131: invalid continuation byte.

The problem is while reading from file, the string "Attività Progettuale Di Ottimizzazione Su Reti M" is read as "Attività  Progettuale Di Ottimizzazione Su Reti M" which adds another space. How can I fix this problem?
359 views
closed

3 Answers

Best answer
Ganni02 (4920 points)
1 2 15
by (4.9k points)
selected by
I did not encounter this issue after fixing the encoding when opening the files. Specifically opening them using encoding= 'UTF-8'
andrea.sterbini (207920 points)
750 1267 2373
by (208k points)
Always use the utf8 encoding when opening text files!
Nilats (3750 points)
8 14 29
by (3.8k points)
It's probably the exercise text that is causing this problem, try to delete that.

https://stackoverflow.com/questions/40442264/difference-between-comments-in-python-and
z
zaur (740 points)
3 6 8
by (740 points)
edited by
I think you got it wrong. There is no problem with exercise text. The problem is in the one of the strings of the test. This is the string: "Attività Progettuale Di Ottimizzazione Su Reti M". It causes problem because len of this string is caculated as 49 instead of 48.
Exyss (21510 points)
1 2 79
by (21.5k points)
Are you sure you're opening the files using encoding = Utf8?