Skip to content

Commit a006544

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

File tree

1 file changed

+10
-6
lines changed

1 file changed

+10
-6
lines changed

physics/Bragg_angle.py

+10-6
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,29 @@
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
Returns:
1315
float: The Bragg diffraction angle θ in degrees, rounded to the specified number of decimal places.
14-
16+
1517
Examples:
1618
>>> bragg_angle(2.2e-10, 1, 2.2e-10)
1719
30.0
18-
20+
1921
>>> bragg_angle(5e-10, 2, 1e-10)
2022
11.5
21-
23+
2224
>>> bragg_angle(4e-10, 1, 4e-10)
2325
30.0
24-
26+
2527
# Test case for an invalid sine value (out of range)
2628
>>> bragg_angle(1e-10, 2, 3e-10)
2729
Traceback (most recent call last):
@@ -35,6 +37,8 @@ def bragg_angle(distance: float, order: int, wavelength: float) -> float:
3537
theta_degrees = math.degrees(theta_radians)
3638
return round(theta_degrees, 1)
3739

40+
3841
if __name__ == "__main__":
3942
import doctest
43+
4044
doctest.testmod(verbose=True)

0 commit comments

Comments
 (0)