aakashdevdat commited on
Commit
372fe47
·
verified ·
1 Parent(s): 3ff5f60

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +61 -0
app.py ADDED
@@ -0,0 +1,61 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import math
3
+
4
+ st.set_page_config(page_title="Advanced Calculator", page_icon="🧮")
5
+
6
+ st.title("🧮 Advanced Calculator")
7
+
8
+ # Select operation
9
+ operation = st.selectbox(
10
+ "Select Operation",
11
+ (
12
+ "Add",
13
+ "Subtract",
14
+ "Multiply",
15
+ "Divide",
16
+ "Square",
17
+ "Square Root",
18
+ "Power (x^y)",
19
+ "Log (base 10)"
20
+ )
21
+ )
22
+
23
+ # Input fields
24
+ if operation in ["Add", "Subtract", "Multiply", "Divide", "Power (x^y)"]:
25
+ num1 = st.number_input("Enter first number")
26
+ num2 = st.number_input("Enter second number")
27
+
28
+ elif operation in ["Square", "Square Root", "Log (base 10)"]:
29
+ num1 = st.number_input("Enter number")
30
+
31
+ # Calculate button
32
+ if st.button("Calculate"):
33
+ try:
34
+ if operation == "Add":
35
+ result = num1 + num2
36
+
37
+ elif operation == "Subtract":
38
+ result = num1 - num2
39
+
40
+ elif operation == "Multiply":
41
+ result = num1 * num2
42
+
43
+ elif operation == "Divide":
44
+ result = "Error! Division by zero." if num2 == 0 else num1 / num2
45
+
46
+ elif operation == "Square":
47
+ result = num1 ** 2
48
+
49
+ elif operation == "Square Root":
50
+ result = "Error! Negative number." if num1 < 0 else math.sqrt(num1)
51
+
52
+ elif operation == "Power (x^y)":
53
+ result = num1 ** num2
54
+
55
+ elif operation == "Log (base 10)":
56
+ result = "Error! Input must be > 0." if num1 <= 0 else math.log10(num1)
57
+
58
+ st.success(f"Result: {result}")
59
+
60
+ except Exception as e:
61
+ st.error(f"Error: {e}")