Spaces:
Sleeping
Sleeping
Download app.py from Student3331/calculator: direct link, hf CLI and curl.
- Browser
- Download file 776 Bytes
-
https://huggingface.co/spaces/Student3331/calculator/resolve/main/app.py
- Command line
-
hf download hf://spaces/Student3331/calculator/app.py
-
curl -L -o app.py https://huggingface.co/spaces/Student3331/calculator/resolve/main/app.py
776 Bytes
| import streamlit as st | |
| import math | |
| # Set the title for the app | |
| st.title("Scientific Calculator") | |
| # Input box for the user to enter the expression | |
| expression = st.text_input("Enter the mathematical expression:") | |
| # Available scientific functions | |
| def calculate(expression): | |
| try: | |
| # Evaluate the expression for basic arithmetic operations | |
| result = eval(expression, {"__builtins__": None}, { | |
| 'sin': math.sin, 'cos': math.cos, 'tan': math.tan, | |
| 'sqrt': math.sqrt, 'exp': math.exp, 'log': math.log, | |
| 'pi': math.pi, 'e': math.e, 'log10': math.log10 | |
| }) | |
| return result | |
| except Exception as e: | |
| return "Error: " + str(e) | |
| if expression: | |
| result = calculate(expression) | |
| st.write(f"Result: {result}") | |