Fixed an incorrect numerical comparison in numbers.py #1129
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.
Issue
The original statement (at line 115 of numbers.py) of:
is an invalid numerical comparison which translates to
(number > 1000) and (1000 < 10000). In effect onlynumber > 1000is evaluated, as
1000 < 10000is always True.Affected Public Methods
The primary public method of the file,
normalize_numbers()currently returns an incorrect conversion for numbers that are greater than 10,000 which also satify the conditions(number % 100 == 0)and(number % 1000 != 0).Proposed fix
The proposed fix is to use the correct mathematical form of the comparison as documented in https://docs.python.org/3/reference/expressions.html#comparisons
This results in the correct conversion of numbers greater than 10000, divisible by 100, and indivisible by 1000: