Skip to content

Conversation

stevendes
Copy link
Owner

Completed and ready for review!

@stevendes stevendes requested a review from glpuga January 24, 2020 17:09
Copy link

@AlejoAsd AlejoAsd left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Lots of comments! I went deep into some Python-specific concepts. Please address my code comments to see if my explanations made sense to you.

Comment on lines 38 to 40
repeated_nums = [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]
for number in dice:
repeated_nums[number]=repeated_nums[number] + 1

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Dice have 6 possible values, but the repeated_nums variable in your solution has 10 total values. Was this done because you were getting list index out of range errors when the array had only 6 values, and increasing the size fixed it? If that is the case, then let me explain why.

Sequences (list, tuple, set, string, etc.) in Python and most programming languages are zero-based. This means that the elements are numbered starting at 0. The first element has index 0, the second element has index 1, and so on. When you create repeated_nums with 6 elements, you get the following:

# Index           0  1  2  3  4  5
# Die Value       1  2  3  4  5  6 
# repeated_nums  [0, 0, 0, 0, 0, 0]

The out of index errors were happening because you were iterating over the values of the dice,

for number in dice:

which set number to some value between 1 and 6, but were using this value as an index.

    repeated_nums[number] [...]

The problem here is that values go from 1 to 6, but indexes go from 0 to 5. This means that whenever the value of number is 6, you will get an list index out of range error, because the list does not have an index 6; its maximum index is 5.

A quick solution to this is to substract 1 from the value of the dice, so that both the indexes and dice values are in the same range.

repeated_nums = [0, 0, 0, 0, 0, 0]
for number in dice:
    repeated_nums[number-1] = repeated_nums[number] + 1

Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't even notice this error because for some reason I forgot that the dice goes only to 6 (I did not forget that it can't be 0 tho haha)

So what I was trying to do is to compare the values to the numbers from 1 to 9, when trying to make the list shorter I run with that error, so that fixes it!

@stevendes
Copy link
Owner Author

All comments addressed!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants