mirror of
https://github.com/TheAlgorithms/Python.git
synced 2024-11-23 21:11:08 +00:00
Compare commits
6 Commits
3e07e32b83
...
186f0498cb
Author | SHA1 | Date | |
---|---|---|---|
|
186f0498cb | ||
|
f3f32ae3ca | ||
|
e3bd7721c8 | ||
|
e3f3d668be | ||
|
8368803dac | ||
|
6f127c6b8d |
|
@ -16,7 +16,7 @@ repos:
|
|||
- id: auto-walrus
|
||||
|
||||
- repo: https://github.com/astral-sh/ruff-pre-commit
|
||||
rev: v0.7.2
|
||||
rev: v0.7.4
|
||||
hooks:
|
||||
- id: ruff
|
||||
- id: ruff-format
|
||||
|
@ -42,7 +42,7 @@ repos:
|
|||
pass_filenames: false
|
||||
|
||||
- repo: https://github.com/abravalheri/validate-pyproject
|
||||
rev: v0.22
|
||||
rev: v0.23
|
||||
hooks:
|
||||
- id: validate-pyproject
|
||||
|
||||
|
|
|
@ -172,7 +172,7 @@ def solved(values):
|
|||
|
||||
def from_file(filename, sep="\n"):
|
||||
"Parse a file into a list of strings, separated by sep."
|
||||
return open(filename).read().strip().split(sep) # noqa: SIM115
|
||||
return open(filename).read().strip().split(sep)
|
||||
|
||||
|
||||
def random_puzzle(assignments=17):
|
||||
|
|
33
physics/rotational_partition
Normal file
33
physics/rotational_partition
Normal file
|
@ -0,0 +1,33 @@
|
|||
def rotation_partition_function(moment_of_inertia: float,
|
||||
temperature: float) -> float:
|
||||
"""
|
||||
Calculates the rotational partition
|
||||
function for linear molecules.
|
||||
|
||||
>>> round(rotation_partition_function(1e-46, 300), 4)
|
||||
5.9275
|
||||
>>> round(rotation_partition_function(2e-46, 300), 4)
|
||||
11.855
|
||||
>>> round(rotation_partition_function(-2e-46, 300), 4)
|
||||
Traceback (most recent call last):
|
||||
...
|
||||
ValueError: Moment of inertia must be positive
|
||||
>>> round(rotation_partition_function(1e-46, -300), 4)
|
||||
Traceback (most recent call last):
|
||||
...
|
||||
ValueError: Temperature must be positive
|
||||
"""
|
||||
|
||||
if moment_of_inertia <= 0:
|
||||
raise ValueError("Moment of inertia must be positive")
|
||||
if temperature <= 0:
|
||||
raise ValueError("Temperature must be positive")
|
||||
|
||||
k_B = 1.380649e-23 # Boltzmann constant
|
||||
h = 6.62607015e-34 # Planck's constant
|
||||
|
||||
return (2 * math.pi * moment_of_inertia * k_B * temperature) / (h ** 2)
|
||||
|
||||
if __name__ == "__main__":
|
||||
import doctest
|
||||
doctest.testmod(name="rotation_partition_function")
|
|
@ -1,4 +1,4 @@
|
|||
#!/usr/bin/env python3
|
||||
#!python
|
||||
import os
|
||||
|
||||
try:
|
||||
|
|
Loading…
Reference in New Issue
Block a user