CoolFace
Apppublic

Rimsha63/Calculator

sourceHugging Facemitupdated 2y agoView on Hugging Face
0likes
app.py55 linesDownload Raw Back to root
1import streamlit as st2 3def main():4    st.title("Extended Simple Calculator")5 6    # User input: Three numbers7    num1 = st.number_input("Enter first number:", value=0.0, format="%.2f")8    num2 = st.number_input("Enter second number:", value=0.0, format="%.2f")9    num3 = st.number_input("Enter third number:", value=0.0, format="%.2f")10 11    # Operation selection12    operation = st.selectbox(13        "Choose an operation:",14        ("Addition", "Subtraction", "Multiplication", "Division", "Modulus", "Exponentiation", "Floor Division")15    )16 17    # Calculation and result18    result = None19 20    if st.button("Calculate"):21        try:22            if operation == "Addition":23                result = num1 + num2 + num324            elif operation == "Subtraction":25                result = num1 - num2 - num326            elif operation == "Multiplication":27                result = num1 * num2 * num328            elif operation == "Division":29                if num2 == 0 or num3 == 0:30                    st.error("Error: Division by zero is not allowed!")31                else:32                    result = num1 / num2 / num333            elif operation == "Modulus":34                if num2 == 0 or num3 == 0:35                    st.error("Error: Modulus by zero is not allowed!")36                else:37                    result = num1 % num2 % num338            elif operation == "Exponentiation":39                result = num1 ** num2 ** num340            elif operation == "Floor Division":41                if num2 == 0 or num3 == 0:42                    st.error("Error: Floor division by zero is not allowed!")43                else:44                    result = num1 // num2 // num345 46            if result is not None:47                st.success(f"Result: {result}")48 49        except Exception as e:50            st.error(f"Error: {e}")51 52if __name__ == "__main__":53    main()54 55