import streamlit as st import sympy as sp # Function for arithmetic operations def addition(a, b): return a + b def subtraction(a, b): return a - b def multiplication(a, b): return a * b def division(a, b): if b == 0: return "Cannot divide by zero!" return a / b # Function for calculating area of shapes def calculate_area(shape, *params): if shape.lower() == 'circle': # Area of circle = π * r^2 radius = params[0] return sp.pi * radius**2 elif shape.lower() == 'rectangle': # Area of rectangle = length * width length, width = params return length * width elif shape.lower() == 'triangle': # Area of triangle = 1/2 * base * height base, height = params return 0.5 * base * height else: return "Shape not recognized!" # Main Streamlit app def math_teacher(): st.title("Math Teacher Program") # Sidebar for navigation st.sidebar.title("Navigation") app_mode = st.sidebar.radio("Choose a mode", ["Arithmetic", "Geometry"]) if app_mode == "Arithmetic": st.subheader("Arithmetic Operations") a = st.number_input("Enter first number:", value=0.0) b = st.number_input("Enter second number:", value=0.0) operation = st.selectbox("Select operation", ["+", "-", "*", "/"]) if st.button("Calculate"): if operation == "+": result = addition(a, b) elif operation == "-": result = subtraction(a, b) elif operation == "*": result = multiplication(a, b) elif operation == "/": result = division(a, b) st.write(f"Result: {result}") elif app_mode == "Geometry": st.subheader("Geometry Area Calculator") shape = st.selectbox("Choose a shape", ["Circle", "Rectangle", "Triangle"]) if shape == "Circle": radius = st.number_input("Enter the radius of the circle:", value=0.0) if st.button("Calculate Area"): area = calculate_area(shape, radius) st.write(f"Area of the circle: {area}") elif shape == "Rectangle": length = st.number_input("Enter the length of the rectangle:", value=0.0) width = st.number_input("Enter the width of the rectangle:", value=0.0) if st.button("Calculate Area"): area = calculate_area(shape, length, width) st.write(f"Area of the rectangle: {area}") elif shape == "Triangle": base = st.number_input("Enter the base of the triangle:", value=0.0) height = st.number_input("Enter the height of the triangle:", value=0.0) if st.button("Calculate Area"): area = calculate_area(shape, base, height) st.write(f"Area of the triangle: {area}") # Run the Streamlit app if __name__ == "__main__": math_teacher()