mbs1829/Basic_Calculator_test
0
1import streamlit as st2import math3 4def main():5 st.title("🧮 Advanced Calculator")6 7 st.write("This calculator performs basic and advanced math operations.")8 9 num1 = st.number_input("Enter first number:", value=0.0)10 num2 = st.number_input("Enter second number:", value=0.0)11 12 operation = st.selectbox("Choose an operation:", (13 "Addition", 14 "Subtraction", 15 "Multiplication", 16 "Division", 17 "Exponentiation (x^y)",18 "Modulo (x % y)",19 "Square Root (√x)",20 "Absolute Value (|x|, |y|)"21 ))22 23 result = None24 25 if st.button("Calculate"):26 if operation == "Addition":27 result = num1 + num228 elif operation == "Subtraction":29 result = num1 - num230 elif operation == "Multiplication":31 result = num1 * num232 elif operation == "Division":33 if num2 != 0:34 result = num1 / num235 else:36 st.error("Cannot divide by zero!")37 elif operation == "Exponentiation (x^y)":38 result = math.pow(num1, num2)39 elif operation == "Modulo (x % y)":40 if num2 != 0:41 result = num1 % num242 else:43 st.error("Cannot modulo by zero!")44 elif operation == "Square Root (√x)":45 if num1 >= 0:46 result = math.sqrt(num1)47 else:48 st.error("Cannot calculate square root of negative number!")49 elif operation == "Absolute Value (|x|, |y|)":50 result = f"|{num1}| = {abs(num1)}, |{num2}| = {abs(num2)}"51 52 if result is not None:53 st.success(f"Result: {result}")54 55if __name__ == "__main__":56 main()57 