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.

VIDEOLEZIONI DEL CORSO DI FONDAMENTI DI PROGRAMMAZIONE AA20-21

PROGRAMMING COURSE VIDEOCONFERENCES AY20-21

problem in exercise 48 in programming exercises

Simone Russolillo (5790 points)
6 10 22
in Programming in Python by (5.8k points)
recategorized by
good evening professors, sorry to bother,

there must be a problem with the imported modules, it appears to me that not even the solution in the folder can be tested.

AttributeError: 'list' object has no attribute 'BinaryTree'

could you have a look at it? Thanks

thanks for the attention!
162 views
closed

1 Answer

Best answer
andrea.sterbini (173640 points)
516 941 1795
by (174k points)
selected by
  1. rename the file albero.py to tree.py
  2. edit the file replacing AlberoBinario with BinaryTree
  3. save
andrea.sterbini (173640 points)
516 941 1795
by (174k points)
edited by

Moreover you should edit the test.py file and make these changes:

  • change    def do_test(self, tree, expected):
  • to             def do_test(self, root, expected):
  • change         tree1 = tree.BinaryTree.fromList(tree)
  • to                  tree1 = tree.BinaryTree.fromList(root)
  • change     def test(self, tree, expected):
  •                         return self.do_test(tree, expected)
  • to              def test(self, root, expected):
  •                         return self.do_test(root, expected)

And in file solution.py change all es48 to ex48

andrea.sterbini (173640 points)
516 941 1795
by (174k points)
I have updated the zip
Nilats (3750 points)
7 14 29
by (3.8k points)
Hello prof,

I noticed that N67's tests are wrong,

| Given a path in the filesystem, the function recursively explores the corresponding directory and returns a dictionary with the found file extensions as keys and an integer as values.|

Only tests-2 is correct while test-1 and test-3 are incorrect.

I tried copy, pasting the solution.py and I got the same errors of my own program.
andrea.sterbini (173640 points)
516 941 1795
by (174k points)
That's strange. All works fine for me (on Linux).
Nilats (3750 points)
7 14 29
by (3.8k points)
runfile('E:/Scuola/Programming/Esercizi_py/Recursion/N67/test.py', wdir='E:/Scuola/Programming/Esercizi_py/Recursion/N67')
test_1 (__main__.Test) ... Recursion detected in minmax
FAIL
test_2 (__main__.Test) ... Recursion detected in minmax
ok
test_3 (__main__.Test) ... Recursion detected in minmax
ERROR

======================================================================
ERROR: test_3 (__main__.Test)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "E:\Anaconda\lib\site-packages\ddt.py", line 182, in wrapper
    return func(self, *args, **kwargs)
  File "E:\Scuola\Programming\Esercizi_py\Recursion\N67\test.py", line 47, in test
    return self.do_test(path, expected)
  File "E:\Scuola\Programming\Esercizi_py\Recursion\N67\test.py", line 31, in do_test
    result = program.es67(path)
  File "E:\Scuola\Programming\Esercizi_py\Recursion\N67\testlib.py", line 21, in __exit__
    raise TimeoutError(f"Timeout ({tempo} > {self.timeout})")
testlib.TimeoutError: Timeout (4.689 > 2)

======================================================================
FAIL: test_1 (__main__.Test)
----------------------------------------------------------------------
Traceback (most recent call last):
  File "E:\Anaconda\lib\site-packages\ddt.py", line 182, in wrapper
    return func(self, *args, **kwargs)
  File "E:\Scuola\Programming\Esercizi_py\Recursion\N67\test.py", line 47, in test
    return self.do_test(path, expected)
  File "E:\Scuola\Programming\Esercizi_py\Recursion\N67\test.py", line 34, in do_test
    self.assertEqual(
AssertionError: {'kkk': 5, 'txt': 5, 'www': 4, 'vvv': 1, 'p[212 chars]': 0} != {'www': 4, 'sss': 3, 'nnn': 2, 'uuu': 2, 'z[212 chars]': 0}
  {'aaa': 0,
   'bbb': 1,
   'ccc': 0,
   'ddd': 0,
   'doc': 0,
   'fff': 0,
   'ggg': 2,
   'hhh': 3,
   'iii': 2,
   'jjj': 0,
   'kkk': 5,
   'mmm': 0,
   'nnn': 2,
   'ooo': 0,
   'png': 0,
   'ppp': 1,
   'qqq': 0,
   'rtf': 0,
   'sss': 3,
   'ttt': 3,
-  'txt': 5,
?         ^

+  'txt': 2,
?         ^

   'uuu': 2,
   'vvv': 1,
   'www': 4,
   'xxx': 1,
   'zzz': 0} : Il risultato deve essere {'www': 4, 'sss': 3, 'nnn': 2, 'uuu': 2, 'zzz': 0, 'txt': 2, 'jjj': 0, 'aaa': 0, 'ppp': 1, 'ooo': 0, 'ccc': 0, 'vvv': 1, 'xxx': 1, 'iii': 2, 'bbb': 1, 'ggg': 2, 'png': 0, 'ttt': 3, 'hhh': 3, 'kkk': 5, 'fff': 0, 'mmm': 0, 'rtf': 0, 'qqq': 0, 'doc': 0, 'ddd': 0} invece che {'kkk': 5, 'txt': 5, 'www': 4, 'vvv': 1, 'png': 0, 'bbb': 1, 'iii': 2, 'ppp': 1, 'ggg': 2, 'aaa': 0, 'ttt': 3, 'hhh': 3, 'nnn': 2, 'zzz': 0, 'uuu': 2, 'jjj': 0, 'sss': 3, 'ccc': 0, 'ooo': 0, 'xxx': 1, 'qqq': 0, 'ddd': 0, 'doc': 0, 'fff': 0, 'mmm': 0, 'rtf': 0}

----------------------------------------------------------------------
Ran 3 tests in 5.118s

FAILED (failures=1, errors=1)
2 test passed, 1 tests failed

This is the result I get running the solution.py
andrea.sterbini (173640 points)
516 941 1795
by (174k points)
You get a timeout.

Try removing the timeout check from the test.py file (e.g. enlarging the time available)
Nilats (3750 points)
7 14 29
by (3.8k points)
It still says it's failing and again this is not my program but solution.py
andrea.sterbini (173640 points)
516 941 1795
by (174k points)
When I have time I will try it on Windows