Spaces:
Build error
Build error
Download app.py from Maham930/Calculator: direct link, hf CLI and curl.
- Browser
- Download file 772 Bytes
-
https://huggingface.co/spaces/Maham930/Calculator/resolve/main/app.py
- Command line
-
hf download hf://spaces/Maham930/Calculator/app.py
-
curl -L -o app.py https://huggingface.co/spaces/Maham930/Calculator/resolve/main/app.py
772 Bytes
| # app.py | |
| import streamlit as st | |
| # Title of the app | |
| st.title("\U0001F9EE Simple Calculator App") | |
| # User inputs | |
| num1 = st.number_input("Enter first number", value=0.0) | |
| num2 = st.number_input("Enter second number", value=0.0) | |
| # Operation selection | |
| operation = st.selectbox("Choose an operation", ["Add", "Subtract", "Multiply", "Divide"]) | |
| # Perform calculation | |
| def calculate(n1, n2, op): | |
| if op == "Add": | |
| return n1 + n2 | |
| elif op == "Subtract": | |
| return n1 - n2 | |
| elif op == "Multiply": | |
| return n1 * n2 | |
| elif op == "Divide": | |
| if n2 == 0: | |
| return "Error: Division by zero" | |
| return n1 / n2 | |
| # Display result | |
| if st.button("Calculate"): | |
| result = calculate(num1, num2, operation) | |
| st.success(f"Result: {result}") | |