forked from gregmalcolm/python_koans
-
Notifications
You must be signed in to change notification settings - Fork 0
Completed the about_scoring_project koan #25
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
stevendes
wants to merge
2
commits into
devel
Choose a base branch
from
about_scoring_project
base: devel
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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_numsvariable in your solution has 10 total values. Was this done because you were gettinglist index out of rangeerrors 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 createrepeated_numswith 6 elements, you get the following:The out of index errors were happening because you were iterating over the values of the dice,
which set
numberto some value between 1 and 6, but were using this value as an index.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
numberis 6, you will get anlist index out of rangeerror, 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.
There was a problem hiding this comment.
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 be0tho haha)So what I was trying to do is to compare the values to the numbers from
1to9, when trying to make the list shorter I run with that error, so that fixes it!