math calculator app
To upload files, please first save the app
import streamlit as st
import numpy as np
st.title("Math Calculator")
# Input numbers
num1 = st.number_input("Enter first number:", value=0)
num2 = st.number_input("Enter second number:", value=0)
# Select operation
operation = st.selectbox("Select operation:", ["Add", "Subtract", "Multiply", "Divide", "Power", "Square Root", "Logarithm"])
# Calculate result based on selected operation
if operation == "Add":
result = num1 + num2
elif operation == "Subtract":
result = num1 - num2
elif operation == "Multiply":
result = num1 * num2
elif operation == "Divide":
result = num1 / num2 if num2 != 0 else "Cannot divide by zero!"
elif operation == "Power":
result = np.power(num1, num2)
elif operation == "Square Root":
result = np.sqrt(num1)
else:
result = np.log(num1) if num1 > 0 else "Cannot take logarithm of non-positive number!"
# Display result
st.write("Result:", result)
Hi! I can help you with any questions about Streamlit and Python. What would you like to know?