Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
@@ -0,0 +1,27 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
import streamlit as st
|
2 |
+
|
3 |
+
# Set the title of the app
|
4 |
+
st.title('Simple Calculator')
|
5 |
+
|
6 |
+
# Get user inputs for the calculation
|
7 |
+
num1 = st.number_input('Enter first number', value=0)
|
8 |
+
num2 = st.number_input('Enter second number', value=0)
|
9 |
+
|
10 |
+
# Create options for selecting the type of operation
|
11 |
+
operation = st.selectbox('Choose 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 of the calculation
|
27 |
+
st.write(f'The result is: {result}')
|