Shehroz-Ali-02's picture
Update app.py
09e7a8a verified
import streamlit as st
# Set the title of the app
st.title('Extended Calculator')
# Get user inputs for the calculation
num1 = st.number_input('Enter first number', value=0)
num2 = st.number_input('Enter second number', value=0)
num3 = st.number_input('Enter third number', value=0)
# Create options for selecting the type of operation
operation = st.selectbox('Choose operation', ('Add', 'Subtract', 'Multiply', 'Divide', 'Average', 'Exponentiation', 'Modulus'))
# Perform calculation based on the selected operation
if operation == 'Add':
result = num1 + num2 + num3
elif operation == 'Subtract':
result = num1 - num2 - num3
elif operation == 'Multiply':
result = num1 * num2 * num3
elif operation == 'Divide':
if num2 != 0 and num3 != 0:
result = num1 / num2 / num3
else:
result = 'Error! Division by Zero'
elif operation == 'Average':
result = (num1 + num2 + num3) / 3
elif operation == 'Exponentiation':
base = st.number_input('Enter the base number', value=1) # Get base input from the user
exponent = st.number_input('Enter the exponent number', value=1) # Get exponent input from the user
result = base ** exponent # Exponentiation calculation
elif operation == 'Modulus':
if num2 != 0 and num3 != 0:
result = num1 % num2 % num3
else:
result = 'Error! Modulus by Zero'
# Display the result of the calculation
st.write(f'The result is: {result}')