File size: 1,982 Bytes
0d499e8 b30016c 0d499e8 b30016c 0d499e8 b30016c 0d499e8 b30016c 0d499e8 b30016c 0d499e8 b30016c 0d499e8 b30016c 0d499e8 b30016c 0f8360f |
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 |
import streamlit as st
import numpy as np
st.set_page_config(page_title="Advanced Calculator", page_icon="🧮")
st.title("🧮 Advanced Calculator")
# Layout
col1, col2 = st.columns(2)
with col1:
num1 = st.number_input("Enter first number", format="%.5f", step=1.0)
with col2:
num2 = st.number_input("Enter second number (if needed)", format="%.5f", step=1.0)
# Operation selection
operation = st.selectbox(
"Choose an operation",
[
"Add", "Subtract", "Multiply", "Divide",
"Power", "Modulo", "Square Root", "Logarithm",
"Sine", "Cosine", "Tangent"
]
)
# Perform calculation
result = None
if st.button("Calculate"):
try:
if operation == "Add":
result = num1 + num2
elif operation == "Subtract":
result = num1 - num2
elif operation == "Multiply":
result = num1 * num2
elif operation == "Divide":
if num2 != 0:
result = num1 / num2
else:
st.error("Cannot divide by zero.")
elif operation == "Power":
result = np.power(num1, num2)
elif operation == "Modulo":
result = num1 % num2
elif operation == "Square Root":
if num1 >= 0:
result = np.sqrt(num1)
else:
st.error("Cannot take square root of a negative number.")
elif operation == "Logarithm":
if num1 > 0:
result = np.log(num1)
else:
st.error("Logarithm undefined for non-positive values.")
elif operation == "Sine":
result = np.sin(np.radians(num1))
elif operation == "Cosine":
result = np.cos(np.radians(num1))
elif operation == "Tangent":
result = np.tan(np.radians(num1))
except Exception as e:
st.error(f"An error occurred: {e}")
# Display result
if result is not None:
st.success(f"Result: {result}")
|