Create app.py
Browse files
app.py
ADDED
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
|
3 |
+
# Title of the app
|
4 |
+
st.title("Simple Calculator")
|
5 |
+
|
6 |
+
# User input for two numbers
|
7 |
+
num1 = st.number_input("Enter the first number", value=0.0)
|
8 |
+
num2 = st.number_input("Enter the second number", value=0.0)
|
9 |
+
|
10 |
+
# Dropdown for selecting the operation
|
11 |
+
operation = st.selectbox("Select the operation", ("Add", "Subtract", "Multiply", "Divide"))
|
12 |
+
|
13 |
+
# Perform calculation based on the selected operation
|
14 |
+
if operation == "Add":
|
15 |
+
result = num1 + num2
|
16 |
+
elif operation == "Subtract":
|
17 |
+
result = num1 - num2
|
18 |
+
elif operation == "Multiply":
|
19 |
+
result = num1 * num2
|
20 |
+
elif operation == "Divide":
|
21 |
+
if num2 != 0:
|
22 |
+
result = num1 / num2
|
23 |
+
else:
|
24 |
+
result = "Error! Division by zero."
|
25 |
+
|
26 |
+
# Display the result
|
27 |
+
st.write(f"Result: {result}")
|