Spaces:
Sleeping
Sleeping
File size: 2,972 Bytes
d649136 |
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 |
import streamlit as st
import math
# Title of the app
st.title("🧮 Scientific Calculator")
# Description
st.write("Perform various mathematical operations including basic arithmetic, logarithms, trigonometric functions, and more.")
# Dropdown menu for operations
operation = st.selectbox(
"Select an operation:",
[
"Addition",
"Subtraction",
"Multiplication",
"Division",
"Power",
"Square Root",
"Logarithm (base 10)",
"Natural Logarithm (ln)",
"Sine",
"Cosine",
"Tangent"
]
)
# Input fields for operations
if operation in ["Addition", "Subtraction", "Multiplication", "Division", "Power"]:
num1 = st.number_input("Enter the first number:", format="%.2f")
num2 = st.number_input("Enter the second number:", format="%.2f")
if st.button("Calculate"):
if operation == "Addition":
st.success(f"Result: {num1} + {num2} = {num1 + num2}")
elif operation == "Subtraction":
st.success(f"Result: {num1} - {num2} = {num1 - num2}")
elif operation == "Multiplication":
st.success(f"Result: {num1} * {num2} = {num1 * num2}")
elif operation == "Division":
if num2 != 0:
st.success(f"Result: {num1} / {num2} = {num1 / num2}")
else:
st.error("Error: Division by zero is not allowed.")
elif operation == "Power":
st.success(f"Result: {num1} ^ {num2} = {math.pow(num1, num2)}")
elif operation == "Square Root":
num = st.number_input("Enter the number:", format="%.2f")
if st.button("Calculate"):
if num >= 0:
st.success(f"Result: √{num} = {math.sqrt(num)}")
else:
st.error("Error: Square root of a negative number is not allowed.")
elif operation == "Logarithm (base 10)":
num = st.number_input("Enter the number:", format="%.2f")
if st.button("Calculate"):
if num > 0:
st.success(f"Result: log10({num}) = {math.log10(num)}")
else:
st.error("Error: Logarithm is only defined for positive numbers.")
elif operation == "Natural Logarithm (ln)":
num = st.number_input("Enter the number:", format="%.2f")
if st.button("Calculate"):
if num > 0:
st.success(f"Result: ln({num}) = {math.log(num)}")
else:
st.error("Error: Natural logarithm is only defined for positive numbers.")
elif operation in ["Sine", "Cosine", "Tangent"]:
angle = st.number_input("Enter the angle in degrees:", format="%.2f")
if st.button("Calculate"):
radians = math.radians(angle)
if operation == "Sine":
st.success(f"Result: sin({angle}) = {math.sin(radians)}")
elif operation == "Cosine":
st.success(f"Result: cos({angle}) = {math.cos(radians)}")
elif operation == "Tangent":
st.success(f"Result: tan({angle}) = {math.tan(radians)}")
|