|
|
import streamlit as st |
|
|
import math |
|
|
|
|
|
|
|
|
def add(x, y): |
|
|
return x + y |
|
|
|
|
|
def subtract(x, y): |
|
|
return x - y |
|
|
|
|
|
def multiply(x, y): |
|
|
return x * y |
|
|
|
|
|
def divide(x, y): |
|
|
if y == 0: |
|
|
return "Cannot divide by zero" |
|
|
return x / y |
|
|
|
|
|
def power(x, y): |
|
|
return math.pow(x, y) |
|
|
|
|
|
def sqrt(x): |
|
|
return math.sqrt(x) |
|
|
|
|
|
def log10(x): |
|
|
if x <= 0: |
|
|
return "Logarithm undefined for non-positive numbers" |
|
|
return math.log10(x) |
|
|
|
|
|
def loge(x): |
|
|
if x <= 0: |
|
|
return "Natural log undefined for non-positive numbers" |
|
|
return math.log(x) |
|
|
|
|
|
def sine(x): |
|
|
return math.sin(math.radians(x)) |
|
|
|
|
|
def cosine(x): |
|
|
return math.cos(math.radians(x)) |
|
|
|
|
|
def tangent(x): |
|
|
return math.tan(math.radians(x)) |
|
|
|
|
|
def factorial(x): |
|
|
if x < 0: |
|
|
return "Factorial undefined for negative numbers" |
|
|
return math.factorial(int(x)) |
|
|
|
|
|
def absolute(x): |
|
|
return abs(x) |
|
|
|
|
|
|
|
|
st.title("Scientific Calculator") |
|
|
|
|
|
|
|
|
num1 = st.number_input("Enter the first number:", value=0.0) |
|
|
num2 = st.number_input("Enter the second number:", value=0.0) |
|
|
|
|
|
|
|
|
operation = st.selectbox( |
|
|
"Select an operation", |
|
|
["Add", "Subtract", "Multiply", "Divide", "Power", "Square Root", "log10", "ln", "Sine", "Cosine", "Tangent", "Factorial", "Absolute"] |
|
|
) |
|
|
|
|
|
|
|
|
if operation == "Add": |
|
|
result = add(num1, num2) |
|
|
elif operation == "Subtract": |
|
|
result = subtract(num1, num2) |
|
|
elif operation == "Multiply": |
|
|
result = multiply(num1, num2) |
|
|
elif operation == "Divide": |
|
|
result = divide(num1, num2) |
|
|
elif operation == "Power": |
|
|
result = power(num1, num2) |
|
|
elif operation == "Square Root": |
|
|
result = sqrt(num1) |
|
|
elif operation == "log10": |
|
|
result = log10(num1) |
|
|
elif operation == "ln": |
|
|
result = loge(num1) |
|
|
elif operation == "Sine": |
|
|
result = sine(num1) |
|
|
elif operation == "Cosine": |
|
|
result = cosine(num1) |
|
|
elif operation == "Tangent": |
|
|
result = tangent(num1) |
|
|
elif operation == "Factorial": |
|
|
result = factorial(num1) |
|
|
elif operation == "Absolute": |
|
|
result = absolute(num1) |
|
|
|
|
|
|
|
|
st.write(f"The result of {operation} is: {result}") |
|
|
|