MCPcopy Create free account
hub / github.com/TheAlgorithms/Python / period_of_pendulum

Function period_of_pendulum

physics/period_of_pendulum.py:30–47  ·  view source on GitHub ↗

>>> period_of_pendulum(1.23) 2.2252155506257845 >>> period_of_pendulum(2.37) 3.0888278441908574 >>> period_of_pendulum(5.63) 4.76073193364765 >>> period_of_pendulum(-12) Traceback (most recent call last): ... ValueError: The length should be non-negative

(length: float)

Source from the content-addressed store, hash-verified

28
29
30def period_of_pendulum(length: float) -> float:
31 """
32 >>> period_of_pendulum(1.23)
33 2.2252155506257845
34 >>> period_of_pendulum(2.37)
35 3.0888278441908574
36 >>> period_of_pendulum(5.63)
37 4.76073193364765
38 >>> period_of_pendulum(-12)
39 Traceback (most recent call last):
40 ...
41 ValueError: The length should be non-negative
42 >>> period_of_pendulum(0)
43 0.0
44 """
45 if length < 0:
46 raise ValueError("The length should be non-negative")
47 return 2 * pi * (length / g) ** 0.5
48
49
50if __name__ == "__main__":

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected