CoolFace
Apppublic

HudaRaja/SimpleCalculator

sourceHugging Facemitupdated 1y agoView on Hugging Face
0likes
app.py31 linesDownload Raw Back to root
1import streamlit as st2 3# Title of the app4st.title("Simple Calculator")5 6# Input fields7num1 = st.number_input("Enter first number", value=0.0)8num2 = st.number_input("Enter second number", value=0.0)9 10# Operation selection11operation = st.selectbox("Select operation", ("Add", "Subtract", "Multiply", "Divide"))12 13# Perform calculation14result = None15if st.button("Calculate"):16    if operation == "Add":17        result = num1 + num218    elif operation == "Subtract":19        result = num1 - num220    elif operation == "Multiply":21        result = num1 * num222    elif operation == "Divide":23        if num2 != 0:24            result = num1 / num225        else:26            st.error("Cannot divide by zero")27 28# Display result29if result is not None:30    st.success(f"Result: {result}")31