Maham930 commited on
Commit
b7bcd93
·
verified ·
1 Parent(s): bd7713f

Create app.py

Browse files

Correct app.py

Files changed (1) hide show
  1. app.py +30 -0
app.py ADDED
@@ -0,0 +1,30 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ # app.py
2
+ import streamlit as st
3
+
4
+ # Title of the app
5
+ st.title("\U0001F9EE Simple Calculator App")
6
+
7
+ # User inputs
8
+ num1 = st.number_input("Enter first number", value=0.0)
9
+ num2 = st.number_input("Enter second number", value=0.0)
10
+
11
+ # Operation selection
12
+ operation = st.selectbox("Choose an operation", ["Add", "Subtract", "Multiply", "Divide"])
13
+
14
+ # Perform calculation
15
+ def calculate(n1, n2, op):
16
+ if op == "Add":
17
+ return n1 + n2
18
+ elif op == "Subtract":
19
+ return n1 - n2
20
+ elif op == "Multiply":
21
+ return n1 * n2
22
+ elif op == "Divide":
23
+ if n2 == 0:
24
+ return "Error: Division by zero"
25
+ return n1 / n2
26
+
27
+ # Display result
28
+ if st.button("Calculate"):
29
+ result = calculate(num1, num2, operation)
30
+ st.success(f"Result: {result}")