├── .gitignore ├── README.md ├── .github └── workflows │ └── update-readme.yml ├── LICENSE └── calculator.py /.gitignore: -------------------------------------------------------------------------------- 1 | __pycache__/ 2 | *.pyc 3 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Python Calculator 🧮 2 | 3 | A simple command-line calculator built with Python. 4 | 5 | ## Features: 6 | - Addition ➕ 7 | - Subtraction ➖ 8 | - Multiplication ✖️ 9 | - Division ➗ (with zero-check) 10 | 11 | ## How to Run: 12 | 1. Make sure you have Python 3 installed. 13 | 2. Clone this repository: 14 | --- 15 | 16 | 📅 Last updated: 2025-12-17 17 | -------------------------------------------------------------------------------- /.github/workflows/update-readme.yml: -------------------------------------------------------------------------------- 1 | name: Update README 2 | 3 | on: 4 | schedule: 5 | - cron: "0 0 * * *" # Запуск каждый день в 00:00 UTC 6 | workflow_dispatch: # Позволяет запускать вручную 7 | 8 | jobs: 9 | update-readme: 10 | runs-on: ubuntu-latest 11 | steps: 12 | - name: Checkout репозиторий 13 | uses: actions/checkout@v4 14 | 15 | - name: Обновление даты в README.md 16 | run: | 17 | TODAY=$(date "+%Y-%m-%d") 18 | sed -i "s/.*/ $TODAY/" README.md 19 | 20 | - name: Коммит изменений 21 | run: | 22 | git config --global user.name "github-actions" 23 | git config --global user.email "actions@github.com" 24 | git add README.md 25 | git commit -m "Автообновление даты: $TODAY" || echo "Изменений нет" 26 | git push 27 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2025 A.Ostrovskis 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /calculator.py: -------------------------------------------------------------------------------- 1 | import colorama 2 | from colorama import Fore, Style 3 | import math 4 | 5 | colorama.init(autoreset=True) 6 | 7 | def add(x, y): 8 | return x + y 9 | 10 | def subtract(x, y): 11 | return x - y 12 | 13 | def multiply(x, y): 14 | return x * y 15 | 16 | def divide(x, y): 17 | if y == 0: 18 | return Fore.RED + "Error: Division by zero! Please try again with a non-zero denominator." 19 | return x / y 20 | 21 | def power(x, y): 22 | return x ** y 23 | 24 | def square_root(x): 25 | if x < 0: 26 | return Fore.RED + "Error: Cannot compute square root of negative number." 27 | return math.sqrt(x) 28 | 29 | def main(): 30 | print(Fore.CYAN + Style.BRIGHT + "Simple Python Calculator") 31 | print(Fore.YELLOW + "1. Addition (+)") 32 | print(Fore.YELLOW + "2. Subtraction (-)") 33 | print(Fore.YELLOW + "3. Multiplication (*)") 34 | print(Fore.YELLOW + "4. Division (/)") 35 | print(Fore.YELLOW + "5. Power (^)") 36 | print(Fore.YELLOW + "6. Square Root (√)") 37 | 38 | while True: 39 | choice = input(Fore.MAGENTA + "Enter choice (1/2/3/4/5/6) or 'q' to quit: ") 40 | 41 | if choice == 'q': 42 | print(Fore.GREEN + "Exiting calculator. Goodbye!") 43 | break 44 | 45 | if choice in ('1', '2', '3', '4', '5', '6'): 46 | try: 47 | num1 = float(input(Fore.BLUE + "Enter first number: ")) 48 | if choice in ('1', '2', '3', '4', '5'): 49 | num2 = float(input(Fore.BLUE + "Enter second number: ")) 50 | except ValueError: 51 | print(Fore.RED + "Error: Please enter valid numbers!") 52 | continue 53 | 54 | if choice == '1': 55 | print(Fore.GREEN + f"Result: {num1} + {num2} = {add(num1, num2)}") 56 | elif choice == '2': 57 | print(Fore.GREEN + f"Result: {num1} - {num2} = {subtract(num1, num2)}") 58 | elif choice == '3': 59 | print(Fore.GREEN + f"Result: {num1} * {num2} = {multiply(num1, num2)}") 60 | elif choice == '4': 61 | print(Fore.GREEN + f"Result: {num1} / {num2} = {divide(num1, num2)}") 62 | elif choice == '5': 63 | print(Fore.GREEN + f"Result: {num1} ^ {num2} = {power(num1, num2)}") 64 | elif choice == '6': 65 | print(Fore.GREEN + f"Result: √{num1} = {square_root(num1)}") 66 | else: 67 | print(Fore.RED + "Error: Invalid choice!") 68 | 69 | if __name__ == "__main__": 70 | main() 71 | 72 | --------------------------------------------------------------------------------