nimra2019 commited on
Commit
aaa02e9
·
verified ·
1 Parent(s): d588679

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +30 -0
app.py ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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:", ["Add", "Subtract", "Multiply", "Divide"])
8
+ num2 = st.number_input("Enter second number:", format="%.2f")
9
+
10
+ # Perform calculation
11
+ if st.button("Calculate"):
12
+ try:
13
+ if operation == "Add":
14
+ result = num1 + num2
15
+ elif operation == "Subtract":
16
+ result = num1 - num2
17
+ elif operation == "Multiply":
18
+ result = num1 * num2
19
+ elif operation == "Divide":
20
+ if num2 != 0:
21
+ result = num1 / num2
22
+ else:
23
+ st.error("Cannot divide by zero.")
24
+ result = None
25
+
26
+ if result is not None:
27
+ st.success(f"Result: {result:.2f}")
28
+
29
+ except Exception as e:
30
+ st.error(f"An error occurred: {e}")