Spaces:
Sleeping
Sleeping
Create ankith.py
Browse files
ankith.py
ADDED
@@ -0,0 +1,38 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
|
3 |
+
st.title("Calculator App using Streamlit")
|
4 |
+
|
5 |
+
# creates a horizontal line
|
6 |
+
st.write("---")
|
7 |
+
|
8 |
+
# input 1
|
9 |
+
num1 = st.number_input(label="Enter first number")
|
10 |
+
|
11 |
+
# input 2
|
12 |
+
num2 = st.number_input(label="Enter second number")
|
13 |
+
|
14 |
+
st.write("Operation")
|
15 |
+
|
16 |
+
operation = st.radio("Select an operation to perform:",
|
17 |
+
("Add", "Subtract", "Multiply", "Divide"))
|
18 |
+
|
19 |
+
ans = 0
|
20 |
+
|
21 |
+
|
22 |
+
def calculate():
|
23 |
+
if operation == "Add":
|
24 |
+
ans = num1 + num2
|
25 |
+
elif operation == "Subtract":
|
26 |
+
ans = num1 - num2
|
27 |
+
elif operation == "Multiply":
|
28 |
+
ans = num1 * num2
|
29 |
+
elif operation == "Divide" and num2 != 0:
|
30 |
+
ans = num1 / num2
|
31 |
+
else:
|
32 |
+
st.warning("Division by 0 error. Please enter a non-zero number.")
|
33 |
+
ans = "Not defined"
|
34 |
+
|
35 |
+
st.success(f"Answer = {ans}")
|
36 |
+
|
37 |
+
if st.button("Calculate result"):
|
38 |
+
calculate()
|