Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions maths/volume_of_cylinder.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import math

Check failure on line 1 in maths/volume_of_cylinder.py

View workflow job for this annotation

GitHub Actions / ruff

ruff (I001)

maths/volume_of_cylinder.py:1:1: I001 Import block is un-sorted or un-formatted help: Organize imports

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")

Check failure on line 18 in maths/volume_of_cylinder.py

View workflow job for this annotation

GitHub Actions / ruff

ruff (W293)

maths/volume_of_cylinder.py:18:1: W293 Blank line contains whitespace help: Remove whitespace from blank line
volume = math.pi * (radius ** 2) * height
return round(volume, 2)

if __name__ == "__main__":
import doctest
doctest.testmod()

Check failure on line 24 in maths/volume_of_cylinder.py

View workflow job for this annotation

GitHub Actions / ruff

ruff (W292)

maths/volume_of_cylinder.py:24:22: W292 No newline at end of file help: Add trailing newline
Loading