Spaces:
Build error
Build error
File size: 3,005 Bytes
4b16756 | 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 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 | 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()
|