mirror of
https://github.com/TheAlgorithms/Python.git
synced 2026-03-13 09:50:19 +08:00
Fix ruff errors (#8936)
* Fix ruff errors
Renamed neural_network/input_data.py to neural_network/input_data.py_tf
because it should be left out of the directory for the following
reasons:
1. Its sole purpose is to be used by neural_network/gan.py_tf, which is
itself left out of the directory because of issues with TensorFlow.
2. It was taken directly from TensorFlow's codebase and is actually
already deprecated. If/when neural_network/gan.py_tf is eventually
re-added back to the directory, its implementation should be changed
to not use neural_network/input_data.py anyway.
* updating DIRECTORY.md
* Change input_data.py_tf file extension
Change input_data.py_tf file extension because algorithms-keeper bot is being picky about it
---------
Co-authored-by: github-actions <${GITHUB_ACTOR}@users.noreply.github.com>
This commit is contained in:
@@ -22,9 +22,13 @@ REFERENCES :
|
||||
-> Wikipedia reference: https://en.wikipedia.org/wiki/Millimeter
|
||||
"""
|
||||
|
||||
from collections import namedtuple
|
||||
from typing import NamedTuple
|
||||
|
||||
|
||||
class FromTo(NamedTuple):
|
||||
from_factor: float
|
||||
to_factor: float
|
||||
|
||||
from_to = namedtuple("from_to", "from_ to")
|
||||
|
||||
TYPE_CONVERSION = {
|
||||
"millimeter": "mm",
|
||||
@@ -40,14 +44,14 @@ TYPE_CONVERSION = {
|
||||
}
|
||||
|
||||
METRIC_CONVERSION = {
|
||||
"mm": from_to(0.001, 1000),
|
||||
"cm": from_to(0.01, 100),
|
||||
"m": from_to(1, 1),
|
||||
"km": from_to(1000, 0.001),
|
||||
"in": from_to(0.0254, 39.3701),
|
||||
"ft": from_to(0.3048, 3.28084),
|
||||
"yd": from_to(0.9144, 1.09361),
|
||||
"mi": from_to(1609.34, 0.000621371),
|
||||
"mm": FromTo(0.001, 1000),
|
||||
"cm": FromTo(0.01, 100),
|
||||
"m": FromTo(1, 1),
|
||||
"km": FromTo(1000, 0.001),
|
||||
"in": FromTo(0.0254, 39.3701),
|
||||
"ft": FromTo(0.3048, 3.28084),
|
||||
"yd": FromTo(0.9144, 1.09361),
|
||||
"mi": FromTo(1609.34, 0.000621371),
|
||||
}
|
||||
|
||||
|
||||
@@ -115,7 +119,11 @@ def length_conversion(value: float, from_type: str, to_type: str) -> float:
|
||||
f"Conversion abbreviations are: {', '.join(METRIC_CONVERSION)}"
|
||||
)
|
||||
raise ValueError(msg)
|
||||
return value * METRIC_CONVERSION[new_from].from_ * METRIC_CONVERSION[new_to].to
|
||||
return (
|
||||
value
|
||||
* METRIC_CONVERSION[new_from].from_factor
|
||||
* METRIC_CONVERSION[new_to].to_factor
|
||||
)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
@@ -19,19 +19,23 @@ REFERENCES :
|
||||
-> https://www.unitconverters.net/pressure-converter.html
|
||||
"""
|
||||
|
||||
from collections import namedtuple
|
||||
from typing import NamedTuple
|
||||
|
||||
|
||||
class FromTo(NamedTuple):
|
||||
from_factor: float
|
||||
to_factor: float
|
||||
|
||||
from_to = namedtuple("from_to", "from_ to")
|
||||
|
||||
PRESSURE_CONVERSION = {
|
||||
"atm": from_to(1, 1),
|
||||
"pascal": from_to(0.0000098, 101325),
|
||||
"bar": from_to(0.986923, 1.01325),
|
||||
"kilopascal": from_to(0.00986923, 101.325),
|
||||
"megapascal": from_to(9.86923, 0.101325),
|
||||
"psi": from_to(0.068046, 14.6959),
|
||||
"inHg": from_to(0.0334211, 29.9213),
|
||||
"torr": from_to(0.00131579, 760),
|
||||
"atm": FromTo(1, 1),
|
||||
"pascal": FromTo(0.0000098, 101325),
|
||||
"bar": FromTo(0.986923, 1.01325),
|
||||
"kilopascal": FromTo(0.00986923, 101.325),
|
||||
"megapascal": FromTo(9.86923, 0.101325),
|
||||
"psi": FromTo(0.068046, 14.6959),
|
||||
"inHg": FromTo(0.0334211, 29.9213),
|
||||
"torr": FromTo(0.00131579, 760),
|
||||
}
|
||||
|
||||
|
||||
@@ -71,7 +75,9 @@ def pressure_conversion(value: float, from_type: str, to_type: str) -> float:
|
||||
+ ", ".join(PRESSURE_CONVERSION)
|
||||
)
|
||||
return (
|
||||
value * PRESSURE_CONVERSION[from_type].from_ * PRESSURE_CONVERSION[to_type].to
|
||||
value
|
||||
* PRESSURE_CONVERSION[from_type].from_factor
|
||||
* PRESSURE_CONVERSION[to_type].to_factor
|
||||
)
|
||||
|
||||
|
||||
|
||||
@@ -18,35 +18,39 @@ REFERENCES :
|
||||
-> Wikipedia reference: https://en.wikipedia.org/wiki/Cup_(unit)
|
||||
"""
|
||||
|
||||
from collections import namedtuple
|
||||
from typing import NamedTuple
|
||||
|
||||
|
||||
class FromTo(NamedTuple):
|
||||
from_factor: float
|
||||
to_factor: float
|
||||
|
||||
from_to = namedtuple("from_to", "from_ to")
|
||||
|
||||
METRIC_CONVERSION = {
|
||||
"cubicmeter": from_to(1, 1),
|
||||
"litre": from_to(0.001, 1000),
|
||||
"kilolitre": from_to(1, 1),
|
||||
"gallon": from_to(0.00454, 264.172),
|
||||
"cubicyard": from_to(0.76455, 1.30795),
|
||||
"cubicfoot": from_to(0.028, 35.3147),
|
||||
"cup": from_to(0.000236588, 4226.75),
|
||||
"cubic meter": FromTo(1, 1),
|
||||
"litre": FromTo(0.001, 1000),
|
||||
"kilolitre": FromTo(1, 1),
|
||||
"gallon": FromTo(0.00454, 264.172),
|
||||
"cubic yard": FromTo(0.76455, 1.30795),
|
||||
"cubic foot": FromTo(0.028, 35.3147),
|
||||
"cup": FromTo(0.000236588, 4226.75),
|
||||
}
|
||||
|
||||
|
||||
def volume_conversion(value: float, from_type: str, to_type: str) -> float:
|
||||
"""
|
||||
Conversion between volume units.
|
||||
>>> volume_conversion(4, "cubicmeter", "litre")
|
||||
>>> volume_conversion(4, "cubic meter", "litre")
|
||||
4000
|
||||
>>> volume_conversion(1, "litre", "gallon")
|
||||
0.264172
|
||||
>>> volume_conversion(1, "kilolitre", "cubicmeter")
|
||||
>>> volume_conversion(1, "kilolitre", "cubic meter")
|
||||
1
|
||||
>>> volume_conversion(3, "gallon", "cubicyard")
|
||||
>>> volume_conversion(3, "gallon", "cubic yard")
|
||||
0.017814279
|
||||
>>> volume_conversion(2, "cubicyard", "litre")
|
||||
>>> volume_conversion(2, "cubic yard", "litre")
|
||||
1529.1
|
||||
>>> volume_conversion(4, "cubicfoot", "cup")
|
||||
>>> volume_conversion(4, "cubic foot", "cup")
|
||||
473.396
|
||||
>>> volume_conversion(1, "cup", "kilolitre")
|
||||
0.000236588
|
||||
@@ -54,7 +58,7 @@ def volume_conversion(value: float, from_type: str, to_type: str) -> float:
|
||||
Traceback (most recent call last):
|
||||
...
|
||||
ValueError: Invalid 'from_type' value: 'wrongUnit' Supported values are:
|
||||
cubicmeter, litre, kilolitre, gallon, cubicyard, cubicfoot, cup
|
||||
cubic meter, litre, kilolitre, gallon, cubic yard, cubic foot, cup
|
||||
"""
|
||||
if from_type not in METRIC_CONVERSION:
|
||||
raise ValueError(
|
||||
@@ -66,7 +70,11 @@ def volume_conversion(value: float, from_type: str, to_type: str) -> float:
|
||||
f"Invalid 'to_type' value: {to_type!r}. Supported values are:\n"
|
||||
+ ", ".join(METRIC_CONVERSION)
|
||||
)
|
||||
return value * METRIC_CONVERSION[from_type].from_ * METRIC_CONVERSION[to_type].to
|
||||
return (
|
||||
value
|
||||
* METRIC_CONVERSION[from_type].from_factor
|
||||
* METRIC_CONVERSION[to_type].to_factor
|
||||
)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
Reference in New Issue
Block a user