Using range(len(...))
is not pythonic. Python does not have not index-based loops. Instead, it uses collection iterators. Python has a built-in method enumerate
which adds a counter to an iterable.
Too many decision blocks were found, which is why the code has been tagged as complex. You should consider refactoring the code for simplicity. Read more about cyclomatic complexity here.
Calculating the length of the hypotenuse using the standard formula c = sqrt(a**2 + b**2)
may lead to overflow if the two other sides are both very large. Even though c
will not be much bigger than max(a, b)
, either a**2
or b**2
(or both) could be. Thus, the calculation could overflow, even though the result is well within representable range. It is recommended to use the built-in function hypot(a,b)
from the math
library.
The boolean expression with redundant pre-python 2.5 ternary syntax is used and can be simplified for better readability. Please look at the issue text for suggestion.
delete
statement in a local scope PTC-W0043Passing a local variable to a del
statement results in that variable being removed from the local namespace. When exiting a function all local variables are deleted, so it is unnecessary to explicitly delete variables in such cases.