mirror of
https://github.com/TheAlgorithms/Python.git
synced 2024-11-23 21:11:08 +00:00
Compare commits
5 Commits
1bdf83f30e
...
3aaf6dc088
Author | SHA1 | Date | |
---|---|---|---|
|
3aaf6dc088 | ||
|
e3bd7721c8 | ||
|
e3f3d668be | ||
|
4200aa200b | ||
|
4fbdd8e171 |
|
@ -16,7 +16,7 @@ repos:
|
|||
- id: auto-walrus
|
||||
|
||||
- repo: https://github.com/astral-sh/ruff-pre-commit
|
||||
rev: v0.7.2
|
||||
rev: v0.7.3
|
||||
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):
|
||||
|
|
48
physics/translation_partition
Normal file
48
physics/translation_partition
Normal file
|
@ -0,0 +1,48 @@
|
|||
import math
|
||||
|
||||
def translation_partition_function(mass: float, temperature: float,
|
||||
volume: float) -> float:
|
||||
"""
|
||||
Calculates the translational partition
|
||||
function using the formula:
|
||||
q_trans = ((2 * pi * m * k_B * T)^(3/2) * V) / h^3
|
||||
|
||||
mass: Mass of the molecule in kg
|
||||
temperature: Temperature in Kelvin
|
||||
volume: Volume in cubic meters
|
||||
|
||||
>>> round(translation_partition_function(2e-26, 300, 1e-3), 4)
|
||||
4.081816847078438e+28
|
||||
>>> round(translation_partition_function(4e-26, 300, 1e-3), 4)
|
||||
1.1545121488522627e+29
|
||||
>>> round(translation_partition_function(-4e-26, 300, 1e-3), 4)
|
||||
Traceback (most recent call last):
|
||||
...
|
||||
ValueError: Mass must be positive
|
||||
>>> round(translation_partition_function(4e-26, 0, 1e-3), 4)
|
||||
Traceback (most recent call last):
|
||||
...
|
||||
ValueError: Temperature must be positive
|
||||
>>> round(translation_partition_function(4e-26, 300, 0), 4)
|
||||
Traceback (most recent call last):
|
||||
...
|
||||
ValueError: Volume must be positive
|
||||
"""
|
||||
|
||||
if mass <= 0:
|
||||
raise ValueError("Mass must be positive")
|
||||
if temperature <= 0:
|
||||
raise ValueError("Temperature must be positive")
|
||||
if volume <= 0:
|
||||
raise ValueError("Volume must be positive")
|
||||
|
||||
h = 6.62607015e-34 # Planck's constant in J·s
|
||||
k_B = 1.380649e-23 # Boltzmann constant in J/K
|
||||
|
||||
prefactor = (2 * math.pi * mass * k_B * temperature) ** (3 / 2)
|
||||
denominator = h ** 3
|
||||
return (prefactor * volume) / denominator
|
||||
|
||||
if __name__ == "__main__":
|
||||
import doctest
|
||||
doctest.testmod(name="translation_partition_function")
|
|
@ -1,4 +1,4 @@
|
|||
#!/usr/bin/env python3
|
||||
#!python
|
||||
import os
|
||||
|
||||
try:
|
||||
|
|
Loading…
Reference in New Issue
Block a user