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

Do you need help?

[HOMEWORK] HW 1 (optional)

andrea.sterbini (207940 points)
756 1270 2377
in News by (208k points)
edited by

NOTICE

  • corrections to the exercise text will be posted here
    • the example initially talks about '3,0,4,0,3,1,0,1,0,0,5,0,4,2' but there is a 0,1 missing and should be read instead as it's written in the lines that follow: '3,0,4,0,3,1,0,1,0,1,0,0,5,0,4,2'
  • NOTICE: the function you should implement is named ex1 instead of es1
  • NOTICE: the test_01.py program DISABLES the print function, thus you will not see any printed output. To re-enable prints, delete the following highlighted lines:

        with self.ignored_function('builtins.print'), \
                self.ignored_function('pprint.pprint'), \

                self.forbidden_function('builtins.input'), \
                self.timeout(1), \
                self.timer(1):
            result = program.ex1(test_int_seq, test_subtotal)

obtaining

        with self.forbidden_function('builtins.input'), \
                self.timeout(1), \
                self.timer(1):
            result = program.ex1(test_int_seq, test_subtotal)

Instructions

To complete the homework:

  • Install all required libraries
  • Download file HW1opt.zip and unzip it in a directory
    • The archive contains:
      • a problem to be solved, described at the beginning of file program01.py
        • your job is to complete the ex1 function inside program01.py to solve the problem. Adding other functions is allowed.
      • all other libraries and test files needed to run tests on your machine
  • Enter the HW1opt directory created by unzipping the archive and edit program01.py
  • 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).
  • DO NOT LEAVE YOUR TEST FUNCTIONS INSIDE THE PROGRAM, UNLESS THEY ARE AFTER THE LINE
    • if __name__ == '__main__':
      • # Here you can enter your own test instructions
  • To test your program:
    • open an "Anaconda Prompt" window and enter the HW1opt directory
    • run the command
      • pytest test_01.py -v -rA
    • or (test printing also a list of the slowest tests)
      • pytest test_01.py -v -rA --durations 0
    • or (test printing a list of the 20 slowest functions executed)
      • pytest test_01.py -v -rA --profile
    • To stop tests at the first error add the -x option
    • If you use Spyder:
      • 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 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.

Submission

You must submit ONLY the program01.py file

To do so, go to page https://q2a.di.uniroma1.it/homeworks/delivery?homework=1 and submit your file

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.

There is no deadline

  • This homework has no deadline, no peer-assessment, no bonus.

2 Answers

DDave (530 points)
0 0 3
by (530 points)
Hi! Are we supposed to solve this using only the concepts explained thus far or can we use literally everything as long as it's python? Thanks!
andrea.sterbini (207940 points)
756 1270 2377
by (208k points)
Everything is good
DDave (530 points)
0 0 3
by (530 points)
Ok, thank you!
B
Bruni1933963 (1160 points)
0 0 4
by (1.2k points)
reshown by
Hello. I just wanted to point out that in the example

int_seq = '3,0,4,0,3,1,0,1,0,0,5,0,4,2'      [return 9]

but then when the substrings are shown it becomes  

int_seq = '3,0,4,0,3,1,0,1,0,1,0,0,5,0,4,2' (there is one more '0,1') [return 7]

I was trying to check my code with this example and it wasn'tworking.I hope this helps someone that is struggling just like I was.
andrea.sterbini (207940 points)
756 1270 2377
by (208k points)
Thanks, I have added a note above