Aliashraf commited on
Commit
e136138
·
verified ·
1 Parent(s): dd43dc7

Update app.py

Browse files
Files changed (1) hide show
  1. app.py +33 -0
app.py CHANGED
@@ -0,0 +1,33 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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, format="%f")
8
+ num2 = st.number_input("Enter second number", value=0.0, format="%f")
9
+
10
+ # Operation selection
11
+ operation = st.selectbox("Choose operation", ["Add", "Subtract", "Multiply", "Divide"])
12
+
13
+ result = None
14
+
15
+ # Perform calculation
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("Division by zero is not allowed")
28
+ result = "Undefined"
29
+
30
+ st.success(f"Result: {result}")
31
+
32
+ if __name__ == "__main__":
33
+ main()