Nikhil4712 commited on
Commit
b68d2f4
1 Parent(s): 53fe105

Create app.py

Browse files
Files changed (1) hide show
  1. app.py +39 -0
app.py ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ import streamlit as st
2
+
3
+ # Define backend functions for calculations
4
+ def add(a, b):
5
+ return a + b
6
+
7
+ def subtract(a, b):
8
+ return a - b
9
+
10
+ def multiply(a, b):
11
+ return a * b
12
+
13
+ def divide(a, b):
14
+ if b != 0:
15
+ return a / b
16
+ else:
17
+ return "Error! Division by zero."
18
+
19
+ # Streamlit frontend
20
+ st.title("Simple Calculator")
21
+
22
+ st.write("Choose operation:")
23
+ operation = st.selectbox("Operation", ("Add", "Subtract", "Multiply", "Divide"))
24
+
25
+ num1 = st.number_input("Enter first number", value=0.0, format="%f")
26
+ num2 = st.number_input("Enter second number", value=0.0, format="%f")
27
+
28
+ if st.button("Calculate"):
29
+ if operation == "Add":
30
+ result = add(num1, num2)
31
+ elif operation == "Subtract":
32
+ result = subtract(num1, num2)
33
+ elif operation == "Multiply":
34
+ result = multiply(num1, num2)
35
+ elif operation == "Divide":
36
+ result = divide(num1, num2)
37
+
38
+ st.write(f"Result: {result}")
39
+