Make a calculator app
To upload files, please first save the app
import streamlit as st
import numpy as np
st.title('Simple Calculator')
# Create a form for input
with st.form(key='calc_form'):
num1 = st.number_input('Enter the first number:', value=0.0)
operation = st.selectbox('Select operation:', ['Add', 'Subtract', 'Multiply', 'Divide'])
num2 = st.number_input('Enter the second number:', value=0.0)
submit_button = st.form_submit_button(label='Calculate')
# Perform calculation
if submit_button:
if operation == 'Add':
result = np.add(num1, num2)
elif operation == 'Subtract':
result = np.subtract(num1, num2)
elif operation == 'Multiply':
result = np.multiply(num1, num2)
elif operation == 'Divide':
if num2 == 0:
result = 'Error! Division by zero.'
else:
result = np.divide(num1, num2)
st.write('Result:', result)
Hi! I can help you with any questions about Streamlit and Python. What would you like to know?