parent
be8b24da14
commit
404b6e175f
42
classes.py
42
classes.py
|
@ -35,16 +35,16 @@ class DiceCup:
|
|||
dice.throw()
|
||||
|
||||
def total(self):
|
||||
return sum([dice.value for dice in self.dices])
|
||||
return sum(dice.value for dice in self.dices)
|
||||
|
||||
def mean(self):
|
||||
return mean([dice.value for dice in self.dices])
|
||||
return mean(dice.value for dice in self.dices)
|
||||
|
||||
|
||||
def show_graph():
|
||||
cup = DiceCup([Dice() for _ in range(1000)])
|
||||
results = {}
|
||||
for i in range(10000):
|
||||
for _ in range(10_000):
|
||||
cup.shake()
|
||||
try:
|
||||
results[cup.total()] = results[cup.total()] + 1
|
||||
|
@ -55,24 +55,24 @@ def show_graph():
|
|||
plt.show()
|
||||
|
||||
|
||||
def dist_from_origin(x, y):
|
||||
"""Compute distance between a point and the origin."""
|
||||
return (x**2 + y**2) ** 0.5
|
||||
|
||||
|
||||
def dist(x1, y1, x2, y2):
|
||||
"""Compute distance between two points."""
|
||||
return ((x1 - x2) ** 2 + (y1 - y2) ** 2) ** 0.5
|
||||
|
||||
|
||||
def dist_from_origin(point):
|
||||
"""Compute distance between a point and the origin."""
|
||||
return (point["x"] ** 2 + point["y"] ** 2) ** 0.5
|
||||
|
||||
|
||||
def dist(p1, p2):
|
||||
"""Compute distance between two points."""
|
||||
return ((p1["x"] - p2["x"]) ** 2 + (p1["y"] - p2["y"]) ** 2) ** 0.5
|
||||
# def dist_from_origin(x, y):
|
||||
# """Compute distance between a point and the origin."""
|
||||
# return (x**2 + y**2) ** 0.5
|
||||
#
|
||||
#
|
||||
# def dist(x1, y1, x2, y2):
|
||||
# """Compute distance between two points."""
|
||||
# return ((x1 - x2) ** 2 + (y1 - y2) ** 2) ** 0.5
|
||||
#
|
||||
#
|
||||
# def dist_from_origin(point):
|
||||
# """Compute distance between a point and the origin."""
|
||||
# return (point["x"] ** 2 + point["y"] ** 2) ** 0.5
|
||||
#
|
||||
#
|
||||
# def dist(p1, p2):
|
||||
# """Compute distance between two points."""
|
||||
# return ((p1["x"] - p2["x"]) ** 2 + (p1["y"] - p2["y"]) ** 2) ** 0.5
|
||||
|
||||
|
||||
def dist_from_origin(point):
|
||||
|
|
|
@ -11,4 +11,11 @@ ensemble_en_intension = {i for i in range(0, 100) if i % 3 == 0 or i % 5 == 0}
|
|||
print({i: i**2 for i in range(0, 100) if i % 3 == 0 or i % 5 == 0})
|
||||
|
||||
|
||||
recettes = [
|
||||
{"durée": 10},
|
||||
{"durée": 12},
|
||||
{"durée": 14},
|
||||
{"durée": 60},
|
||||
]
|
||||
|
||||
durées = [recette["durée"] for recette in recettes]
|
||||
|
|
12
point.py
12
point.py
|
@ -1,14 +1,20 @@
|
|||
"""Demo implementation of a simple Point class."""
|
||||
|
||||
|
||||
class Point:
|
||||
def __init__(self, x, y): # Dunder init "Double underscore init"
|
||||
"""A 2D point."""
|
||||
|
||||
def __init__(self, x: float, y: float): # Dunder init "Double underscore init"
|
||||
self.x = x
|
||||
self.y = y
|
||||
|
||||
def __repr__(self):
|
||||
return f"Point(x={self.x}, y={self.y})"
|
||||
|
||||
def dist_from_origin(self):
|
||||
def dist_from_origin(self) -> float:
|
||||
"""Compute distance between self and origin."""
|
||||
return (self.x**2 + self.y**2) ** 0.5
|
||||
|
||||
def dist(self, other):
|
||||
def dist(self, other) -> float:
|
||||
"""Compute distance between two points."""
|
||||
return ((self.x - other.x) ** 2 + (self.y - other.y) ** 2) ** 0.5
|
||||
|
|
|
@ -0,0 +1,31 @@
|
|||
[tox]
|
||||
envlist = py3{7,8,9,10,11,12,13}, mypy, black, pylint, isort, ruff
|
||||
isolated_build = True
|
||||
skip_missing_interpreters = True
|
||||
|
||||
[testenv]
|
||||
deps =
|
||||
pytest
|
||||
hypothesis
|
||||
skip_install = True
|
||||
commands = python -m pytest
|
||||
|
||||
[testenv:black]
|
||||
deps = black
|
||||
commands = black --check --diff tests/ point.py
|
||||
|
||||
[testenv:mypy]
|
||||
deps = mypy
|
||||
commands = mypy --ignore-missing-imports point.py
|
||||
|
||||
[testenv:pylint]
|
||||
deps = pylint
|
||||
commands = pylint point.py
|
||||
|
||||
[testenv:isort]
|
||||
deps = isort
|
||||
commands = isort --check --profile=black point.py
|
||||
|
||||
[testenv:ruff]
|
||||
deps = ruff
|
||||
commands = ruff check point.py
|
Loading…
Reference in New Issue