amnashoukat commited on
Commit
cebb882
·
verified ·
1 Parent(s): 44fd972

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +29 -0
app.py ADDED
@@ -0,0 +1,29 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+
3
+ def main():
4
+ st.title("Simple Calculator")
5
+
6
+ num1 = st.number_input("Enter first number", format="%f")
7
+ num2 = st.number_input("Enter second number", format="%f")
8
+
9
+ operation = st.selectbox("Select operation", ("Add", "Subtract", "Multiply", "Divide"))
10
+
11
+ if st.button("Calculate"):
12
+ if operation == "Add":
13
+ result = num1 + num2
14
+ st.success(f"Result: {result}")
15
+ elif operation == "Subtract":
16
+ result = num1 - num2
17
+ st.success(f"Result: {result}")
18
+ elif operation == "Multiply":
19
+ result = num1 * num2
20
+ st.success(f"Result: {result}")
21
+ elif operation == "Divide":
22
+ if num2 != 0:
23
+ result = num1 / num2
24
+ st.success(f"Result: {result}")
25
+ else:
26
+ st.error("Cannot divide by zero!")
27
+
28
+ if __name__ == "__main__":
29
+ main()