Spaces:
Build error
Build error
Download app.py from nightprogrammer/coders_hangout: direct link, hf CLI and curl.
- Browser
- Download file 1.8 kB
-
https://huggingface.co/spaces/nightprogrammer/coders_hangout/resolve/main/app.py
- Command line
-
hf download hf://spaces/nightprogrammer/coders_hangout/app.py
-
curl -L -o app.py https://huggingface.co/spaces/nightprogrammer/coders_hangout/resolve/main/app.py
1.8 kB
| import streamlit as st | |
| import math | |
| # Title of the web app | |
| st.title("β¨ Enhanced Calculator β¨") | |
| # Dropdown menu for operation selection with emojis | |
| operation = st.selectbox( | |
| "Select an operation:", | |
| ["β Addition", "β Subtraction", "βοΈ Multiplication", "β Division", "π’ Exponentiation", "π Square Root"] | |
| ) | |
| # Number inputs based on the selected operation | |
| if operation in ["β Addition", "β Subtraction", "βοΈ Multiplication", "β Division", "π’ Exponentiation"]: | |
| num1 = st.number_input("Enter the first number: π·οΈ", value=0.0) | |
| num2 = st.number_input("Enter the second number: π·οΈ", value=0.0) | |
| if st.button("π Calculate"): | |
| if operation == "β Addition": | |
| result = num1 + num2 | |
| st.success(f"β Result: {result}") | |
| elif operation == "β Subtraction": | |
| result = num1 - num2 | |
| st.success(f"β Result: {result}") | |
| elif operation == "βοΈ Multiplication": | |
| result = num1 * num2 | |
| st.success(f"β Result: {result}") | |
| elif operation == "β Division": | |
| if num2 != 0: | |
| result = num1 / num2 | |
| st.success(f"β Result: {result}") | |
| else: | |
| st.error("π« Error: Division by zero is not allowed!") | |
| elif operation == "π’ Exponentiation": | |
| result = math.pow(num1, num2) | |
| st.success(f"β Result: {result}") | |
| elif operation == "π Square Root": | |
| num = st.number_input("Enter the number: π·οΈ", value=0.0) | |
| if st.button("π Calculate"): | |
| if num >= 0: | |
| result = math.sqrt(num) | |
| st.success(f"β Result: {result}") | |
| else: | |
| st.error("π« Error: Cannot calculate the square root of a negative number!") |