Skip to content

Commit aff6698

Browse files
[pre-commit.ci] auto fixes from pre-commit.com hooks
for more information, see https://pre-commit.ci
1 parent c3cc048 commit aff6698

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

physics/bragg_angle.py

+9-5
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,26 @@
11
import math
2+
3+
24
def bragg_angle(distance: float, order: int, wavelength: float) -> float:
35
"""
46
Calculate the Bragg diffraction angle using the formula:
57
sin(θ) = (n * λ) / (2 * d)
6-
8+
79
Parameters:
810
distance d (float): Distance between crystal planes (in meters).
911
order n (int): Order of reflection.
1012
wavelength λ (float): Wavelength of the radiation (in meters).
11-
13+
1214
Examples:
1315
>>> bragg_angle(2.2e-10, 1, 2.2e-10)
1416
30.0
15-
17+
1618
>>> bragg_angle(5e-10, 2, 1e-10)
1719
11.5
18-
20+
1921
>>> bragg_angle(4e-10, 1, 4e-10)
2022
30.0
21-
23+
2224
# Test case for an invalid sine value (out of range)
2325
>>> bragg_angle(1e-10, 2, 3e-10)
2426
Traceback (most recent call last):
@@ -32,6 +34,8 @@ def bragg_angle(distance: float, order: int, wavelength: float) -> float:
3234
theta_degrees = math.degrees(theta_radians)
3335
return round(theta_degrees, 1)
3436

37+
3538
if __name__ == "__main__":
3639
import doctest
40+
3741
doctest.testmod(verbose=True)

0 commit comments

Comments
 (0)