AmnaHassan commited on
Commit
0d499e8
·
verified ·
1 Parent(s): 4d01a01

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +31 -0
app.py ADDED
@@ -0,0 +1,31 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+
3
+ st.set_page_config(page_title="Simple Calculator", page_icon="🧮")
4
+
5
+ st.title("🧮 Simple Calculator")
6
+
7
+ # Input numbers
8
+ num1 = st.number_input("Enter first number", format="%.2f", step=1.0)
9
+ num2 = st.number_input("Enter second number", format="%.2f", step=1.0)
10
+
11
+ # Operation selection
12
+ operation = st.selectbox("Choose an operation", ["Add", "Subtract", "Multiply", "Divide"])
13
+
14
+ # Calculate result
15
+ result = None
16
+ if st.button("Calculate"):
17
+ if operation == "Add":
18
+ result = num1 + num2
19
+ elif operation == "Subtract":
20
+ result = num1 - num2
21
+ elif operation == "Multiply":
22
+ result = num1 * num2
23
+ elif operation == "Divide":
24
+ if num2 != 0:
25
+ result = num1 / num2
26
+ else:
27
+ st.error("Cannot divide by zero!")
28
+
29
+ # Display result
30
+ if result is not None:
31
+ st.success(f"Result: {result}")