Dua Rajper commited on
Commit
bd70e40
·
verified ·
1 Parent(s): a75976f

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +74 -0
app.py ADDED
@@ -0,0 +1,74 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import math
2
+ import streamlit as st
3
+
4
+ def scientific_calculator():
5
+ st.title("Scientific Calculator")
6
+
7
+ st.sidebar.header("Select Operation")
8
+ operations = [
9
+ "Addition",
10
+ "Subtraction",
11
+ "Multiplication",
12
+ "Division",
13
+ "Exponentiation",
14
+ "Square Root",
15
+ "Sine",
16
+ "Cosine",
17
+ "Tangent",
18
+ "Logarithm (base 10)",
19
+ "Natural Logarithm"
20
+ ]
21
+ operation = st.sidebar.selectbox("Choose an operation:", operations)
22
+
23
+ if operation in ["Addition", "Subtraction", "Multiplication", "Division", "Exponentiation"]:
24
+ num1 = st.number_input("Enter first number:", value=0.0)
25
+ num2 = st.number_input("Enter second number:", value=0.0)
26
+
27
+ if operation == "Addition":
28
+ st.write(f"Result: {num1} + {num2} = {num1 + num2}")
29
+ elif operation == "Subtraction":
30
+ st.write(f"Result: {num1} - {num2} = {num1 - num2}")
31
+ elif operation == "Multiplication":
32
+ st.write(f"Result: {num1} × {num2} = {num1 * num2}")
33
+ elif operation == "Division":
34
+ if num2 == 0:
35
+ st.error("Error: Division by zero!")
36
+ else:
37
+ st.write(f"Result: {num1} ÷ {num2} = {num1 / num2}")
38
+ elif operation == "Exponentiation":
39
+ st.write(f"Result: {num1} ^ {num2} = {num1 ** num2}")
40
+
41
+ elif operation == "Square Root":
42
+ num = st.number_input("Enter a number:", value=0.0)
43
+ if num < 0:
44
+ st.error("Error: Cannot calculate the square root of a negative number!")
45
+ else:
46
+ st.write(f"Result: √{num} = {math.sqrt(num)}")
47
+
48
+ elif operation in ["Sine", "Cosine", "Tangent"]:
49
+ angle = st.number_input("Enter the angle in degrees:", value=0.0)
50
+ radians = math.radians(angle)
51
+
52
+ if operation == "Sine":
53
+ st.write(f"Result: sin({angle}) = {math.sin(radians)}")
54
+ elif operation == "Cosine":
55
+ st.write(f"Result: cos({angle}) = {math.cos(radians)}")
56
+ elif operation == "Tangent":
57
+ st.write(f"Result: tan({angle}) = {math.tan(radians)}")
58
+
59
+ elif operation == "Logarithm (base 10)":
60
+ num = st.number_input("Enter a number:", value=0.0)
61
+ if num <= 0:
62
+ st.error("Error: Logarithm undefined for non-positive numbers!")
63
+ else:
64
+ st.write(f"Result: log10({num}) = {math.log10(num)}")
65
+
66
+ elif operation == "Natural Logarithm":
67
+ num = st.number_input("Enter a number:", value=0.0)
68
+ if num <= 0:
69
+ st.error("Error: Natural logarithm undefined for non-positive numbers!")
70
+ else:
71
+ st.write(f"Result: ln({num}) = {math.log(num)}")
72
+
73
+ if __name__ == "__main__":
74
+ scientific_calculator()