Tanseer45203 commited on
Commit
72f3253
·
verified ·
1 Parent(s): f51dfdd

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +69 -0
app.py ADDED
@@ -0,0 +1,69 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import numpy as np
3
+
4
+ # Title of the app
5
+ st.title("Scientific Calculator")
6
+
7
+ # Input field for numbers
8
+ num1 = st.number_input("Enter a number", value=0.0, format="%.5f")
9
+
10
+ # Scientific operations
11
+ operation = st.selectbox("Select Operation", [
12
+ "Addition", "Subtraction", "Multiplication", "Division",
13
+ "Square", "Square Root", "Power", "Logarithm", "Exponential",
14
+ "Sine", "Cosine", "Tangent", "Factorial"
15
+ ])
16
+
17
+ # Additional input if required
18
+ num2 = None
19
+ if operation in ["Addition", "Subtraction", "Multiplication", "Division", "Power"]:
20
+ num2 = st.number_input("Enter second number", value=0.0, format="%.5f")
21
+
22
+ # Perform Calculation
23
+ result = None
24
+ if st.button("Calculate"):
25
+ try:
26
+ if operation == "Addition":
27
+ result = num1 + num2
28
+ elif operation == "Subtraction":
29
+ result = num1 - num2
30
+ elif operation == "Multiplication":
31
+ result = num1 * num2
32
+ elif operation == "Division":
33
+ if num2 != 0:
34
+ result = num1 / num2
35
+ else:
36
+ st.error("Error: Division by zero is not allowed!")
37
+ elif operation == "Square":
38
+ result = num1 ** 2
39
+ elif operation == "Square Root":
40
+ if num1 >= 0:
41
+ result = np.sqrt(num1)
42
+ else:
43
+ st.error("Error: Square root of a negative number is not allowed!")
44
+ elif operation == "Power":
45
+ result = num1 ** num2
46
+ elif operation == "Logarithm":
47
+ if num1 > 0:
48
+ result = np.log(num1)
49
+ else:
50
+ st.error("Error: Logarithm of zero or a negative number is not allowed!")
51
+ elif operation == "Exponential":
52
+ result = np.exp(num1)
53
+ elif operation == "Sine":
54
+ result = np.sin(np.radians(num1))
55
+ elif operation == "Cosine":
56
+ result = np.cos(np.radians(num1))
57
+ elif operation == "Tangent":
58
+ result = np.tan(np.radians(num1))
59
+ elif operation == "Factorial":
60
+ if num1 >= 0 and num1 == int(num1):
61
+ result = np.math.factorial(int(num1))
62
+ else:
63
+ st.error("Error: Factorial is only defined for non-negative integers!")
64
+ except Exception as e:
65
+ st.error(f"Error: {e}")
66
+
67
+ # Display Result
68
+ if result is not None:
69
+ st.success(f"Result: {result}")