Syed200 commited on
Commit
76d35b1
·
verified ·
1 Parent(s): 4bdad6c

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +59 -1
app.py CHANGED
@@ -1,4 +1,62 @@
1
- import streamlit as st
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
2
 
3
  st.title("Simple Calculator")
4
 
 
1
+ import streamimport streamlit as st
2
+ import math
3
+
4
+ st.title("Advanced Calculator")
5
+
6
+ # Input fields
7
+ num1 = st.number_input("Enter first number", format="%.2f")
8
+ operation = st.selectbox(
9
+ "Select operation",
10
+ ["+", "-", "*", "/", "^ (power)", "% (modulus)", "// (floor division)", "√ (square root)", "log10"]
11
+ )
12
+ num2 = st.number_input("Enter second number", format="%.2f")
13
+
14
+ result = None
15
+ error = None
16
+
17
+ if st.button("Calculate"):
18
+ try:
19
+ if operation == "+":
20
+ result = num1 + num2
21
+ elif operation == "-":
22
+ result = num1 - num2
23
+ elif operation == "*":
24
+ result = num1 * num2
25
+ elif operation == "/":
26
+ if num2 != 0:
27
+ result = num1 / num2
28
+ else:
29
+ error = "Cannot divide by zero"
30
+ elif operation == "^ (power)":
31
+ result = num1 ** num2
32
+ elif operation == "% (modulus)":
33
+ if num2 != 0:
34
+ result = num1 % num2
35
+ else:
36
+ error = "Cannot perform modulus by zero"
37
+ elif operation == "// (floor division)":
38
+ if num2 != 0:
39
+ result = num1 // num2
40
+ else:
41
+ error = "Cannot perform floor division by zero"
42
+ elif operation == "√ (square root)":
43
+ if num1 >= 0:
44
+ result = math.sqrt(num1)
45
+ else:
46
+ error = "Cannot take square root of a negative number"
47
+ elif operation == "log10":
48
+ if num1 > 0:
49
+ result = math.log10(num1)
50
+ else:
51
+ error = "Logarithm defined only for positive numbers"
52
+ except Exception as e:
53
+ error = str(e)
54
+
55
+ if error:
56
+ st.error(error)
57
+ else:
58
+ st.success(f"Result: {result:.4f}")
59
+ lit as st
60
 
61
  st.title("Simple Calculator")
62