Syed200 commited on
Commit
dabb2cb
·
verified ·
1 Parent(s): 0de0365

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +33 -0
app.py ADDED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+
3
+ st.title("Simple Calculator")
4
+
5
+ # Input fields
6
+ num1 = st.number_input("Enter first number", format="%.2f")
7
+ operation = st.selectbox("Select operation", ["+", "-", "*", "/"])
8
+ num2 = st.number_input("Enter second number", format="%.2f")
9
+
10
+ # Perform calculation
11
+ result = None
12
+ error = None
13
+
14
+ if st.button("Calculate"):
15
+ try:
16
+ if operation == "+":
17
+ result = num1 + num2
18
+ elif operation == "-":
19
+ result = num1 - num2
20
+ elif operation == "*":
21
+ result = num1 * num2
22
+ elif operation == "/":
23
+ if num2 != 0:
24
+ result = num1 / num2
25
+ else:
26
+ error = "Cannot divide by zero"
27
+ except Exception as e:
28
+ error = str(e)
29
+
30
+ if error:
31
+ st.error(error)
32
+ else:
33
+ st.success(f"Result: {result:.2f}")