Skip to content

Commit 1317655

Browse files
Fix error messages for horizontal_projectile_motion.py (TheAlgorithms#12722)
* Update horizontal_projectile_motion.py This commit is about logic of this program. Changes made aim to allow a good understanding of what is done. * Update horizontal_projectile_motion.py --------- Co-authored-by: Maxim Smolskiy <mithridatus@mail.ru>
1 parent 47a44ab commit 1317655

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

physics/horizontal_projectile_motion.py

+9-9
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717
"""
1818

1919
# Importing packages
20-
from math import radians as angle_to_radians
20+
from math import radians as deg_to_rad
2121
from math import sin
2222

2323
# Acceleration Constant on Earth (unit m/s^2)
@@ -31,10 +31,10 @@ def check_args(init_velocity: float, angle: float) -> None:
3131

3232
# Ensure valid instance
3333
if not isinstance(init_velocity, (int, float)):
34-
raise TypeError("Invalid velocity. Should be a positive number.")
34+
raise TypeError("Invalid velocity. Should be an integer or float.")
3535

3636
if not isinstance(angle, (int, float)):
37-
raise TypeError("Invalid angle. Range is 1-90 degrees.")
37+
raise TypeError("Invalid angle. Should be an integer or float.")
3838

3939
# Ensure valid angle
4040
if angle > 90 or angle < 1:
@@ -71,7 +71,7 @@ def horizontal_distance(init_velocity: float, angle: float) -> float:
7171
ValueError: Invalid angle. Range is 1-90 degrees.
7272
"""
7373
check_args(init_velocity, angle)
74-
radians = angle_to_radians(2 * angle)
74+
radians = deg_to_rad(2 * angle)
7575
return round(init_velocity**2 * sin(radians) / g, 2)
7676

7777

@@ -94,14 +94,14 @@ def max_height(init_velocity: float, angle: float) -> float:
9494
>>> max_height("a", 20)
9595
Traceback (most recent call last):
9696
...
97-
TypeError: Invalid velocity. Should be a positive number.
97+
TypeError: Invalid velocity. Should be an integer or float.
9898
>>> horizontal_distance(30, "b")
9999
Traceback (most recent call last):
100100
...
101-
TypeError: Invalid angle. Range is 1-90 degrees.
101+
TypeError: Invalid angle. Should be an integer or float.
102102
"""
103103
check_args(init_velocity, angle)
104-
radians = angle_to_radians(angle)
104+
radians = deg_to_rad(angle)
105105
return round(init_velocity**2 * sin(radians) ** 2 / (2 * g), 2)
106106

107107

@@ -128,10 +128,10 @@ def total_time(init_velocity: float, angle: float) -> float:
128128
>>> total_time(30, "b")
129129
Traceback (most recent call last):
130130
...
131-
TypeError: Invalid angle. Range is 1-90 degrees.
131+
TypeError: Invalid angle. Should be an integer or float.
132132
"""
133133
check_args(init_velocity, angle)
134-
radians = angle_to_radians(angle)
134+
radians = deg_to_rad(angle)
135135
return round(2 * init_velocity * sin(radians) / g, 2)
136136

137137

0 commit comments

Comments
 (0)