diff --git a/maths/volume_of_cylinder.py b/maths/volume_of_cylinder.py new file mode 100644 index 000000000000..499c0c9ebe69 --- /dev/null +++ b/maths/volume_of_cylinder.py @@ -0,0 +1,25 @@ +import math + + +def volume_of_cylinder(radius: float, height: float) -> float: + """ + Calculate the volume of a cylinder. + Formula: pi * radius^2 * height + Examples: + >>> volume_of_cylinder(3.0, 5.0) + 141.37 + >>> volume_of_cylinder(2.5, 4.0) + 78.54 + >>> volume_of_cylinder(0.0, 5.0) + 0.0 + """ + if radius < 0 or height < 0: + raise ValueError("Radius and height cannot be negative") + volume = math.pi * (radius**2) * height + return round(volume, 2) + + +if __name__ == "__main__": + import doctest + + doctest.testmod() diff --git a/maths/zellers_congruence.py b/maths/zellers_congruence.py index b958ed3b8659..12ebe6c57f01 100644 --- a/maths/zellers_congruence.py +++ b/maths/zellers_congruence.py @@ -1,5 +1,5 @@ import argparse -import datetime +import datetime as dt def zeller(date_input: str) -> str: @@ -120,7 +120,7 @@ def zeller(date_input: str) -> str: ) # Get datetime obj for validation - dt_ck = datetime.date(int(y), int(m), int(d)) + dt_ck = dt.date(int(y), int(m), int(d)) # Start math if m <= 2: