mirror of
https://github.com/TheAlgorithms/Python.git
synced 2025-07-05 17:34:49 +08:00
[pre-commit.ci] pre-commit autoupdate (#11275)
* [pre-commit.ci] pre-commit autoupdate updates: - [github.com/astral-sh/ruff-pre-commit: v0.1.14 → v0.2.0](https://github.com/astral-sh/ruff-pre-commit/compare/v0.1.14...v0.2.0) * Upgrade pyproject.toml * Revert sudoku_solver.py RUF017 Avoid quadratic list summation --------- Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Christian Clauss <cclauss@me.com>
This commit is contained in:
![66853113+pre-commit-ci[bot]@users.noreply.github.com](/assets/img/avatar_default.png)
committed by
GitHub

parent
4128f19170
commit
ed8d9209da
@ -20,13 +20,11 @@ def resistor_parallel(resistors: list[float]) -> float:
|
||||
"""
|
||||
|
||||
first_sum = 0.00
|
||||
index = 0
|
||||
for resistor in resistors:
|
||||
for index, resistor in enumerate(resistors):
|
||||
if resistor <= 0:
|
||||
msg = f"Resistor at index {index} has a negative or zero value!"
|
||||
raise ValueError(msg)
|
||||
first_sum += 1 / float(resistor)
|
||||
index += 1
|
||||
return 1 / first_sum
|
||||
|
||||
|
||||
@ -44,13 +42,11 @@ def resistor_series(resistors: list[float]) -> float:
|
||||
ValueError: Resistor at index 2 has a negative value!
|
||||
"""
|
||||
sum_r = 0.00
|
||||
index = 0
|
||||
for resistor in resistors:
|
||||
for index, resistor in enumerate(resistors):
|
||||
sum_r += resistor
|
||||
if resistor < 0:
|
||||
msg = f"Resistor at index {index} has a negative value!"
|
||||
raise ValueError(msg)
|
||||
index += 1
|
||||
return sum_r
|
||||
|
||||
|
||||
|
Reference in New Issue
Block a user