AamerAkhter's picture
Create app.py
fb11a1d verified
import streamlit as st
import math
def calculate_cube_volume(side_length):
return side_length ** 3
def calculate_sphere_volume(radius):
return (4/3) * math.pi * (radius ** 3)
def calculate_cylinder_volume(radius, height):
return math.pi * (radius ** 2) * height
def main():
st.title("Simple Volume Calculator")
# Add a sidebar for shape selection
shape = st.sidebar.selectbox(
"Select a shape:",
("Cube", "Sphere", "Cylinder")
)
# Based on the shape selected, show appropriate input fields
if shape == "Cube":
st.header("Cube Volume Calculator")
st.image("https://upload.wikimedia.org/wikipedia/commons/thumb/e/e7/Necker_cube.svg/1200px-Necker_cube.svg.png", width=200)
side_length = st.number_input("Side Length:", min_value=0.1, value=1.0, step=0.1)
if st.button("Calculate Volume"):
volume = calculate_cube_volume(side_length)
st.success(f"The volume of the cube is: {volume:.2f} cubic units")
elif shape == "Sphere":
st.header("Sphere Volume Calculator")
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)
radius = st.number_input("Radius:", min_value=0.1, value=1.0, step=0.1)
if st.button("Calculate Volume"):
volume = calculate_sphere_volume(radius)
st.success(f"The volume of the sphere is: {volume:.2f} cubic units")
elif shape == "Cylinder":
st.header("Cylinder Volume Calculator")
st.image("https://upload.wikimedia.org/wikipedia/commons/thumb/e/e7/Cylinder_geometry.svg/1024px-Cylinder_geometry.svg.png", width=200)
radius = st.number_input("Radius:", min_value=0.1, value=1.0, step=0.1)
height = st.number_input("Height:", min_value=0.1, value=1.0, step=0.1)
if st.button("Calculate Volume"):
volume = calculate_cylinder_volume(radius, height)
st.success(f"The volume of the cylinder is: {volume:.2f} cubic units")
# Add information about the app
st.sidebar.markdown("---")
st.sidebar.info("This is a simple volume calculator app that computes the volume of basic 3D shapes.")
if __name__ == "__main__":
main()