Create app.py
Browse files
app.py
ADDED
|
@@ -0,0 +1,56 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
import streamlit as st
|
| 2 |
+
import math
|
| 3 |
+
|
| 4 |
+
def calculate_cube_volume(side_length):
|
| 5 |
+
return side_length ** 3
|
| 6 |
+
|
| 7 |
+
def calculate_sphere_volume(radius):
|
| 8 |
+
return (4/3) * math.pi * (radius ** 3)
|
| 9 |
+
|
| 10 |
+
def calculate_cylinder_volume(radius, height):
|
| 11 |
+
return math.pi * (radius ** 2) * height
|
| 12 |
+
|
| 13 |
+
def main():
|
| 14 |
+
st.title("Simple Volume Calculator")
|
| 15 |
+
|
| 16 |
+
# Add a sidebar for shape selection
|
| 17 |
+
shape = st.sidebar.selectbox(
|
| 18 |
+
"Select a shape:",
|
| 19 |
+
("Cube", "Sphere", "Cylinder")
|
| 20 |
+
)
|
| 21 |
+
|
| 22 |
+
# Based on the shape selected, show appropriate input fields
|
| 23 |
+
if shape == "Cube":
|
| 24 |
+
st.header("Cube Volume Calculator")
|
| 25 |
+
st.image("https://upload.wikimedia.org/wikipedia/commons/thumb/e/e7/Necker_cube.svg/1200px-Necker_cube.svg.png", width=200)
|
| 26 |
+
side_length = st.number_input("Side Length:", min_value=0.1, value=1.0, step=0.1)
|
| 27 |
+
|
| 28 |
+
if st.button("Calculate Volume"):
|
| 29 |
+
volume = calculate_cube_volume(side_length)
|
| 30 |
+
st.success(f"The volume of the cube is: {volume:.2f} cubic units")
|
| 31 |
+
|
| 32 |
+
elif shape == "Sphere":
|
| 33 |
+
st.header("Sphere Volume Calculator")
|
| 34 |
+
st.image("https://upload.wikimedia.org/wikipedia/commons/thumb/8/87/Sphere_wireframe_10deg_6r.svg/1024px-Sphere_wireframe_10deg_6r.svg.png", width=200)
|
| 35 |
+
radius = st.number_input("Radius:", min_value=0.1, value=1.0, step=0.1)
|
| 36 |
+
|
| 37 |
+
if st.button("Calculate Volume"):
|
| 38 |
+
volume = calculate_sphere_volume(radius)
|
| 39 |
+
st.success(f"The volume of the sphere is: {volume:.2f} cubic units")
|
| 40 |
+
|
| 41 |
+
elif shape == "Cylinder":
|
| 42 |
+
st.header("Cylinder Volume Calculator")
|
| 43 |
+
st.image("https://upload.wikimedia.org/wikipedia/commons/thumb/e/e7/Cylinder_geometry.svg/1024px-Cylinder_geometry.svg.png", width=200)
|
| 44 |
+
radius = st.number_input("Radius:", min_value=0.1, value=1.0, step=0.1)
|
| 45 |
+
height = st.number_input("Height:", min_value=0.1, value=1.0, step=0.1)
|
| 46 |
+
|
| 47 |
+
if st.button("Calculate Volume"):
|
| 48 |
+
volume = calculate_cylinder_volume(radius, height)
|
| 49 |
+
st.success(f"The volume of the cylinder is: {volume:.2f} cubic units")
|
| 50 |
+
|
| 51 |
+
# Add information about the app
|
| 52 |
+
st.sidebar.markdown("---")
|
| 53 |
+
st.sidebar.info("This is a simple volume calculator app that computes the volume of basic 3D shapes.")
|
| 54 |
+
|
| 55 |
+
if __name__ == "__main__":
|
| 56 |
+
main()
|