Spaces:
Sleeping
Sleeping
| import streamlit as st | |
| import numpy as np | |
| import sympy as sp | |
| from sympy import symbols, Eq, solve | |
| st.set_page_config(page_title="🧮 Scientific Calculator", layout="centered") | |
| st.markdown(""" | |
| <style> | |
| .main { | |
| background-color: #f0f2f6; | |
| } | |
| h1 { | |
| color: #4a90e2; | |
| text-align: center; | |
| } | |
| .stButton>button { | |
| background-color: #4a90e2; | |
| color: white; | |
| } | |
| </style> | |
| """, unsafe_allow_html=True) | |
| st.title("🧮 Scientific Calculator") | |
| option = st.selectbox("Choose a calculator mode:", ["Basic Calculator", "Matrix Solver", "Equation Solver"]) | |
| if option == "Basic Calculator": | |
| st.header("Basic Calculator") | |
| expr = st.text_input("Enter expression (e.g., 2*(3+4)/5^2):") | |
| if st.button("Calculate"): | |
| try: | |
| expr = expr.replace("^", "**") | |
| result = eval(expr) | |
| st.success(f"Result: {result}") | |
| except Exception as e: | |
| st.error(f"Error: {e}") | |
| elif option == "Matrix Solver": | |
| st.header("Matrix Solver") | |
| rows = st.number_input("Number of rows", min_value=1, max_value=5, value=2) | |
| cols = st.number_input("Number of columns", min_value=1, max_value=5, value=2) | |
| matrix = [] | |
| st.write("Enter matrix values row-wise:") | |
| for i in range(int(rows)): | |
| row = st.text_input(f"Row {i+1} (comma-separated)") | |
| if row: | |
| matrix.append([float(x) for x in row.split(",")]) | |
| if st.button("Calculate Determinant"): | |
| try: | |
| mat = np.array(matrix) | |
| if mat.shape[0] == mat.shape[1]: | |
| det = np.linalg.det(mat) | |
| st.success(f"Determinant: {det:.2f}") | |
| else: | |
| st.warning("Matrix must be square for determinant calculation.") | |
| except Exception as e: | |
| st.error(f"Error: {e}") | |
| elif option == "Equation Solver": | |
| st.header("Equation Solver") | |
| st.write("Example: x**2 - 4 = 0") | |
| expr = st.text_input("Enter equation:") | |
| var = st.text_input("Enter variable to solve for (e.g., x):") | |
| if st.button("Solve Equation"): | |
| try: | |
| x = symbols(var) | |
| equation = Eq(eval(expr.replace("=", "-")), 0) | |
| sol = solve(equation, x) | |
| st.success(f"Solutions: {sol}") | |
| except Exception as e: | |
| st.error(f"Error: {e}") | |