AamerAkhter commited on
Commit
e38d5ce
·
verified ·
1 Parent(s): 1603d35

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +44 -0
app.py ADDED
@@ -0,0 +1,44 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+
3
+ def main():
4
+ st.set_page_config(page_title="Simple Calculator", page_icon="🧮")
5
+
6
+ st.title("✨ Simple Arithmetic Calculator")
7
+ st.write("Enter two numbers and choose an operator to see the result.")
8
+
9
+ # Layout using columns for a cleaner look
10
+ col1, col2 = st.columns(2)
11
+
12
+ with col1:
13
+ num1 = st.number_input("Enter first number", value=0.0)
14
+ with col2:
15
+ num2 = st.number_input("Enter second number", value=0.0)
16
+
17
+ # Operator selection
18
+ operation = st.selectbox("Choose an operation", ("+", "-", "*", "/"))
19
+
20
+ # Calculation logic
21
+ result = None
22
+ error_msg = None
23
+
24
+ if st.button("Calculate"):
25
+ if operation == "+":
26
+ result = num1 + num2
27
+ elif operation == "-":
28
+ result = num1 - num2
29
+ elif operation == "*":
30
+ result = num1 * num2
31
+ elif operation == "/":
32
+ if num2 != 0:
33
+ result = num1 / num2
34
+ else:
35
+ error_msg = "Cannot divide by zero!"
36
+
37
+ # Display result
38
+ if error_msg:
39
+ st.error(error_msg)
40
+ else:
41
+ st.success(f"**Result:** {result}")
42
+
43
+ if __name__ == "__main__":
44
+ main()