Compare commits

...

6 Commits

Author SHA1 Message Date
nikhitha79
2f610f86e0
Merge 7fa920adfc into e3bd7721c8 2024-11-17 18:36:44 +05:30
Christian Clauss
e3bd7721c8
validate_filenames.py Shebang python for Windows (#12371) 2024-11-15 14:59:14 +01:00
pre-commit-ci[bot]
e3f3d668be
[pre-commit.ci] pre-commit autoupdate (#12370)
* [pre-commit.ci] pre-commit autoupdate

updates:
- [github.com/astral-sh/ruff-pre-commit: v0.7.2 → v0.7.3](https://github.com/astral-sh/ruff-pre-commit/compare/v0.7.2...v0.7.3)
- [github.com/abravalheri/validate-pyproject: v0.22 → v0.23](https://github.com/abravalheri/validate-pyproject/compare/v0.22...v0.23)

* Update sudoku_solver.py

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Christian Clauss <cclauss@me.com>
2024-11-11 21:05:50 +01:00
pre-commit-ci[bot]
3e9ca92ca9
[pre-commit.ci] pre-commit autoupdate (#12349)
updates:
- [github.com/astral-sh/ruff-pre-commit: v0.7.1 → v0.7.2](https://github.com/astral-sh/ruff-pre-commit/compare/v0.7.1...v0.7.2)
- [github.com/tox-dev/pyproject-fmt: v2.4.3 → v2.5.0](https://github.com/tox-dev/pyproject-fmt/compare/v2.4.3...v2.5.0)

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
2024-11-04 21:09:03 +01:00
pre-commit-ci[bot]
7fa920adfc [pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
2024-10-17 17:32:31 +00:00
nikhitha79
e4e9358a35
Create de_broglie
de_broglie wavelength
2024-10-17 23:00:47 +05:30
4 changed files with 51 additions and 5 deletions

View File

@ -16,7 +16,7 @@ repos:
- id: auto-walrus
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.7.1
rev: v0.7.3
hooks:
- id: ruff
- id: ruff-format
@ -29,7 +29,7 @@ repos:
- tomli
- repo: https://github.com/tox-dev/pyproject-fmt
rev: "v2.4.3"
rev: "v2.5.0"
hooks:
- id: pyproject-fmt
@ -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

View File

@ -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):

46
physics/de_broglie Normal file
View File

@ -0,0 +1,46 @@
PLANCK_CONSTANT_JS = 6.62607015e-34 # Planck's constant in Joule-seconds
PLANCK_CONSTANT_EVS = 4.135667696e-15 # Planck's constant in eV-seconds
def de_broglie_wavelength(momentum: float, in_ev: bool = False) -> str:
"""
Calculates the de Broglie wavelength of a particle using the given momentum.
Parameters:
momentum (float): Momentum of the particle.
in_ev (bool, optional): True if momentum is in eV·s.
If False, momentum is in kg·m/s.
Returns:
str: The calculated de Broglie wavelength of the particle in meters,
formatted in scientific notation.
Raises:
ValueError: If the momentum is zero or negative.
Usage example:
>>> de_broglie_wavelength(1e-24)
'6.62607015e-10'
>>> de_broglie_wavelength(1e-24, True)
'4.13566770e+09'
>>> de_broglie_wavelength(0)
Traceback (most recent call last):
...
ValueError: Momentum can't be zero or negative.
>>> de_broglie_wavelength(-1e-24)
Traceback (most recent call last):
...
ValueError: Momentum can't be zero or negative.
>>> de_broglie_wavelength(5e-20)
'1.32521403e-14'
"""
if momentum <= 0:
raise ValueError("Momentum can't be zero or negative.")
wavelength = PLANCK_CONSTANT_EVS / momentum if in_ev else PLANCK_CONSTANT_JS / momentum
return f"{wavelength:.8e}"
if __name__ == "__main__":
import doctest
doctest.testmod()

View File

@ -1,4 +1,4 @@
#!/usr/bin/env python3
#!python
import os
try: