MuhammadKhuram commited on
Commit
4becbda
·
verified ·
1 Parent(s): 8f7ed2e

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +79 -0
app.py ADDED
@@ -0,0 +1,79 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+ import math
3
+
4
+ st.set_page_config(page_title="Advanced Calculator", layout="centered")
5
+
6
+ st.title("🧮 Advanced Calculator")
7
+
8
+ st.write("Supports: +, -, *, /, sqrt, power, log, ln")
9
+
10
+ # Select operation
11
+ operation = st.selectbox(
12
+ "Choose Operation",
13
+ ["Addition (+)", "Subtraction (-)", "Multiplication (*)", "Division (/)",
14
+ "Square Root (sqrt)", "Power (x^y)", "Log base 10 (log)", "Natural Log (ln)"]
15
+ )
16
+
17
+ # Input fields
18
+ if operation in ["Addition (+)", "Subtraction (-)", "Multiplication (*)", "Division (/)"]:
19
+ num1 = st.number_input("Enter first number")
20
+ num2 = st.number_input("Enter second number")
21
+
22
+ elif operation == "Power (x^y)":
23
+ num1 = st.number_input("Enter base")
24
+ num2 = st.number_input("Enter exponent")
25
+
26
+ else:
27
+ num1 = st.number_input("Enter number")
28
+
29
+ # Calculate button
30
+ if st.button("Calculate"):
31
+
32
+ try:
33
+ if operation == "Addition (+)":
34
+ result = num1 + num2
35
+
36
+ elif operation == "Subtraction (-)":
37
+ result = num1 - num2
38
+
39
+ elif operation == "Multiplication (*)":
40
+ result = num1 * num2
41
+
42
+ elif operation == "Division (/)":
43
+ if num2 == 0:
44
+ st.error("Division by zero!")
45
+ else:
46
+ result = num1 / num2
47
+ st.success(f"Result: {result}")
48
+
49
+ elif operation == "Square Root (sqrt)":
50
+ if num1 < 0:
51
+ st.error("Cannot take square root of negative number!")
52
+ else:
53
+ result = math.sqrt(num1)
54
+ st.success(f"Result: {result}")
55
+
56
+ elif operation == "Power (x^y)":
57
+ result = math.pow(num1, num2)
58
+ st.success(f"Result: {result}")
59
+
60
+ elif operation == "Log base 10 (log)":
61
+ if num1 <= 0:
62
+ st.error("Log undefined for non-positive numbers!")
63
+ else:
64
+ result = math.log10(num1)
65
+ st.success(f"Result: {result}")
66
+
67
+ elif operation == "Natural Log (ln)":
68
+ if num1 <= 0:
69
+ st.error("Log undefined for non-positive numbers!")
70
+ else:
71
+ result = math.log(num1)
72
+ st.success(f"Result: {result}")
73
+
74
+ # Show result for basic operations
75
+ if operation in ["Addition (+)", "Subtraction (-)", "Multiplication (*)"]:
76
+ st.success(f"Result: {result}")
77
+
78
+ except Exception as e:
79
+ st.error(f"Error: {e}")