File size: 2,349 Bytes
fb11a1d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
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()