AmnaHassan commited on
Commit
b30016c
·
verified ·
1 Parent(s): 23ca112

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +47 -22
app.py CHANGED
@@ -1,31 +1,56 @@
1
  import streamlit as st
 
2
 
3
- st.set_page_config(page_title="Simple Calculator", page_icon="🧮")
4
 
5
- st.title("🧮 Simple Calculator")
6
 
7
- # Input numbers
8
- num1 = st.number_input("Enter first number", format="%.2f", step=1.0)
9
- num2 = st.number_input("Enter second number", format="%.2f", step=1.0)
 
 
 
 
 
10
 
11
  # Operation selection
12
- operation = st.selectbox("Choose an operation", ["Add", "Subtract", "Multiply", "Divide"])
 
 
 
 
 
 
 
13
 
14
- # Calculate result
15
  result = None
 
16
  if st.button("Calculate"):
17
- if operation == "Add":
18
- result = num1 + num2
19
- elif operation == "Subtract":
20
- result = num1 - num2
21
- elif operation == "Multiply":
22
- result = num1 * num2
23
- elif operation == "Divide":
24
- if num2 != 0:
25
- result = num1 / num2
26
- else:
27
- st.error("Cannot divide by zero!")
28
-
29
- # Display result
30
- if result is not None:
31
- st.success(f"Result: {result}")
 
 
 
 
 
 
 
 
 
 
 
 
1
  import streamlit as st
2
+ import numpy as np
3
 
4
+ st.set_page_config(page_title="Advanced Calculator", page_icon="🧮")
5
 
6
+ st.title("🧮 Advanced Calculator")
7
 
8
+ # Layout
9
+ col1, col2 = st.columns(2)
10
+
11
+ with col1:
12
+ num1 = st.number_input("Enter first number", format="%.5f", step=1.0)
13
+
14
+ with col2:
15
+ num2 = st.number_input("Enter second number (if needed)", format="%.5f", step=1.0)
16
 
17
  # Operation selection
18
+ operation = st.selectbox(
19
+ "Choose an operation",
20
+ [
21
+ "Add", "Subtract", "Multiply", "Divide",
22
+ "Power", "Modulo", "Square Root", "Logarithm",
23
+ "Sine", "Cosine", "Tangent"
24
+ ]
25
+ )
26
 
27
+ # Perform calculation
28
  result = None
29
+
30
  if st.button("Calculate"):
31
+ try:
32
+ if operation == "Add":
33
+ result = num1 + num2
34
+ elif operation == "Subtract":
35
+ result = num1 - num2
36
+ elif operation == "Multiply":
37
+ result = num1 * num2
38
+ elif operation == "Divide":
39
+ if num2 != 0:
40
+ result = num1 / num2
41
+ else:
42
+ st.error("Cannot divide by zero.")
43
+ elif operation == "Power":
44
+ result = np.power(num1, num2)
45
+ elif operation == "Modulo":
46
+ result = num1 % num2
47
+ elif operation == "Square Root":
48
+ if num1 >= 0:
49
+ result = np.sqrt(num1)
50
+ else:
51
+ st.error("Cannot take square root of a negative number.")
52
+ elif operation == "Logarithm":
53
+ if num1 > 0:
54
+ result = np.log(num1)
55
+ else:
56
+ st.error("Logarithm undefined for non-pos