Spaces:
Sleeping
Sleeping
Update app.py
Browse files
app.py
CHANGED
|
@@ -1,27 +1,37 @@
|
|
| 1 |
import streamlit as st
|
| 2 |
|
| 3 |
# Set the title of the app
|
| 4 |
-
st.title('
|
| 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}')
|
|
|
|
| 1 |
import streamlit as st
|
| 2 |
|
| 3 |
# Set the title of the app
|
| 4 |
+
st.title('Extended 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 |
+
num3 = st.number_input('Enter third number', value=0)
|
| 10 |
|
| 11 |
# Create options for selecting the type of operation
|
| 12 |
+
operation = st.selectbox('Choose operation', ('Add', 'Subtract', 'Multiply', 'Divide', 'Average', 'Power', 'Modulus'))
|
| 13 |
|
| 14 |
# Perform calculation based on the selected operation
|
| 15 |
if operation == 'Add':
|
| 16 |
+
result = num1 + num2 + num3
|
| 17 |
elif operation == 'Subtract':
|
| 18 |
+
result = num1 - num2 - num3
|
| 19 |
elif operation == 'Multiply':
|
| 20 |
+
result = num1 * num2 * num3
|
| 21 |
elif operation == 'Divide':
|
| 22 |
+
if num2 != 0 and num3 != 0:
|
| 23 |
+
result = num1 / num2 / num3
|
| 24 |
else:
|
| 25 |
result = 'Error! Division by Zero'
|
| 26 |
+
elif operation == 'Average':
|
| 27 |
+
result = (num1 + num2 + num3) / 3
|
| 28 |
+
elif operation == 'Power':
|
| 29 |
+
result = num1 ** num2 ** num3
|
| 30 |
+
elif operation == 'Modulus':
|
| 31 |
+
if num2 != 0 and num3 != 0:
|
| 32 |
+
result = num1 % num2 % num3
|
| 33 |
+
else:
|
| 34 |
+
result = 'Error! Modulus by Zero'
|
| 35 |
|
| 36 |
# Display the result of the calculation
|
| 37 |
st.write(f'The result is: {result}')
|