Do you need help?

Notice Board

Per partecipare al corso di Fondamenti di programmazione 2021-22 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 2021-22 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.



[HOMEWORK] Homework 2 required

andrea.sterbini (173640 points)
516 941 1795
in News by (174k points)
edited by


  • Corrections to the exercise text will be posted here, keep an eye on this page
    • DO NOT change the content of the input arguments. A new test has been added to fail these cases.
    • NOTICE: in the 4th example there is an error (but the final ranking in the text is correct)
      • In the end 0 has 0 challenges, 1 has 1 challenge and 2 has 2 challenges -> 1 has 2 challenges and 2 has 1 challenge
    • NOTICE that I forgot to remove the warp-factor 2 from the ZIP tests, that is applicable only to VM tests. Thus your laptops that surely run faster than the VM have 12s of timeout instead than the 6 planned. To have a better idea of timeouts remove the *2 at the beginning of
    • NOTICE: please remember  that secret tests will be applied after the deadline to compute the final scores.
      Any solution that is based on special patterns that you have noticed in the published tests will likely fail some or all secret tests.
  • NOTICE: to disable some safety checks and the timeout, change by setting DEBUG=True


To complete the homework:

  • Install all the required libraries (INCLUDING stopit)
  • Download the file and unzip it in a directory
    • The archive contains:
      • a problem to be solved, described at the beginning of file;
        • your job is to complete the ex1 function inside to solve the problem – adding other functions is allowed;
      • a file named program01.txt where you should describe your algorithm in English (keep it anonymous: no id/names or source code);
      • all other libraries and test files needed to run tests on your machine.
  • Enter the directory created by unzipping the archive and
    • rename as and edit the file to solve the problem;
    • edit file program01.txt to describe your algorithm.
  • NOTICE: the program should not use input() or print(). All needed parameters are passed to the ex1 function by the test system. Your results are returned to the tests by using return.
  • BEWARE: global variables are forbidden.
  • BEWARE: it's forbidden to import other libraries apart from the ones already imported in the text.
  • NOTICE: your program should be applicable to any correct input (do not exploit data repetitions or particularities).
    • if __name__ == '__main__':
      • # Here you can enter your own test instructions
  • To test your program:
    • open an “Anaconda Prompt” window and enter the directory obtained by unzipping the file
    • run the following command
      • pytest -v -rA
    • or (test printing also a list of the slowest runs)
      • pytest -v -rA --durations 0
    • or (test printing a list of the 20 slowest functions executed)
      • pytest -v -rA --profile
    • To stop tests at the first error, add the -x option
    • If you use Spyder 4: (version 5 is not supported by these plugins)
      • you can run tests from Spyder by first installing the spyder-unittest plugin (but you cannot add parameters to the test execution);
      • you can profile the functions from Spyder by first installing the spyder-line-profiler plugin.

NOTICE: to open and edit text files in the UTF8 format, DO NOT use Notepad (as it does not handle well the Unix linefeed character '\n'). Use Spyder or Notepad++ instead.

First deadline: 23:59 of 6/11/21 (REQUIRED FOR EVERYBODY)

  • The first deadline is strict and EVERYBODY should submit both their files
  • The next day you will be assigned up to 3 anonymous algorithms to assess and suggest improvements
  • Submit your assessments and suggestions by 23:59 of 8/11/21
  • You will receive up to 3 suggestions from your peers
  • You will have time until 23:59 of 10/11/21 to evaluate ALL the suggestions received and then re-submit new, better programs


You are required to submit BOTH the and the program01.txt files
To do so, go to page and submit both files
After some minutes/hours, the homework leaderboard will be updated with your tests results, conducted in a standardized virtual machine.
You can submit your program more than once. The latest submission is the one that counts.

3 Answers

Ganni02 (4920 points)
1 2 15
by (4.9k points)
In Bocca al Lupo guys :))
1909866 (220 points)
1 2 3
by (220 points)
Si può svolgere anche in inglese o sono tenuto a farlo obbligatoriamente in italiano ?
andrea.sterbini (173640 points)
516 941 1795
by (174k points)
Se consegni qui è meglio Inglese perchè al peer-assessment partecipano persone che parlano Inglese
GabrielAlexandru (7760 points)
2 4 29
by (7.8k points)
Thank you professor. I noticed that you wrote in this post that the test values are passed to the program through the ex1 function. In the folder the function is called only ex, both in and There will be some problems in the virtual machine if we keep it as ex or we should change it as ex1?
gianluca5539 (9820 points)
3 6 44
by (9.8k points)
It's fine with ex(), the tests run
TizioCaio95 (470 points)
2 4 6
by (470 points)
When we return the rankings are we supposed to return the points that each contestant gained or only their place in the leaderboard?
amic1010 (1460 points)
1 2 5
by (1.5k points)
No, just the order of the contestants in a list. EX [2,6,7,3,1,0,4,5] (each number relates to the order of the original input list")