Sapna36 commited on
Commit
49f7614
·
verified ·
1 Parent(s): b2ebfd0

Update app.py

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