python-workout icon indicating copy to clipboard operation
python-workout copied to clipboard

Solution to problem 19.2 seems to have a bug

Open inveniam-viam opened this issue 1 year ago • 0 comments

The problem states: "Ask the user to enter integers, separated by spaces. From this input, create a dict whose keys are the factors for each number, and the values are lists containing those of the users’ integers that are multiples of those factors."

For an input of "6 8 15 30 10", according to the question's phrasing, the expected output should be:

    {1: [6, 8, 15, 30, 10],
     2: [6, 8, 30, 10],
     3: [6, 15, 30],
     6: [6, 30],
     4: [8],
     8: [8],
     5: [15, 30, 10],
     15: [15, 30],
     10: [30, 10],
     30: [30]}

Here, the keys are the factors for each of the numbers - values are lists containing numbers from user input that are multiples of said factors.

However the solution when run with the same input string argument returns:

      {6: [1, 2, 3, 6], 
        8: [1, 2, 4, 8],
       15: [1, 3, 5, 15], 
       30: [1, 2, 3, 5, 6, 10, 15, 30]}

The issue with the given solution seems to be that the keys are the users' integers and the values are the factors for each numbers.

inveniam-viam avatar Feb 06 '24 22:02 inveniam-viam