diff --git a/HW2_Islamova/README.md b/HW2_Islamova/README.md new file mode 100644 index 0000000..7ecf0cf --- /dev/null +++ b/HW2_Islamova/README.md @@ -0,0 +1,66 @@ +# Python Calculator + +A simple console-based calculator implementation in Python for basic mathematical operations. +## Features + +- Addition (+) +- Subtraction (-) +- Multiplication (*) +- Division (/) +- Zero division error handling +- Support for negative numbers and floating-point values +- Input validation + +## Installation + +Clone the repository: + + +git clone https://github.com/rentagr/HW2_Git_and_python.git +cd HW2_Git_and_python + +## Usage + +Run the calculator: +python3 HW2_Islamova/calculator.py + +Follow the prompts: + + Enter a mathematical expression (example: 5 - 3): + +The numbers and the operator must be separated by spaces. + +Input first number: a; +Enter math operation: +, -, *, /; +Input second number: b; + + +## Example + + Enter a mathematical expression (example: 5 - 3): 15.5 * 2 + 31 + +## Technologies Used + + Python 3 + + Git version control + + GitHub collaboration + +## Development Team + +Team Members: + + Elena Ivankina - Add function, finding errors and inaccuracies, group communication organization + Anastasia Patrusheva - Sustract function, finding errors and inaccuracies, error correction + Elena Kalita - Multiply funcrion, finding errors and inaccuracies, error correction + Mikhail Dobryakov - Division function implementation with zero division handling, finding errors and inaccuracies + Renata I. Tagirovna - Project regulation, main calculator function, input validation + +![Team](images/Dev_team1.jpg) + +![Symbol](images/snake.jpg) + + +## This is an educational project developed for academic purposes diff --git a/HW2_Islamova/calculator.py b/HW2_Islamova/calculator.py new file mode 100644 index 0000000..3463b9e --- /dev/null +++ b/HW2_Islamova/calculator.py @@ -0,0 +1,73 @@ +# calculator.py + +AVAILABLE_OPERATORS = ['+', '-', '*', '/'] + +def add(a, b): + result = a + b + return result + +def subtract(a, b): + result = a - b + return result + +def multiply(a, b): + result = a * b + return result + +def divide(a, b): + if b == 0: + print("Error: Division by zero is not possible") + return None + result = a / b + return result + +def main (): + while True: + # Getting the input expression from the user + expression = input("Enter a mathematical expression (example: 5 - 3): ") + if not expression: + print("Error: empty input") + continue + # Split the string into parts by spaces + parts = expression.split() + + # Checking the input format + if len(parts) != 3: + print("Error: Incorrect input format") + continue + + # Checking whether the operands are numbers + try: + a = float(parts[0]) + b = float(parts[2]) + except ValueError: + print("Error: the numbers must be numeric or float types") + continue + + # Checking the operand + operator = parts[1] + if operator not in AVAILABLE_OPERATORS: + print(f"Error: unsupported operator '{operator}'. Available operators: {AVAILABLE_OPERATORS}") + continue + + # Select the appropriate function to calculate + if operator == '+': + result = add(a, b) + elif operator == '-': + result = subtract(a, b) + elif operator == '*': + result = multiply(a, b) + elif operator == '/': + result = divide(a, b) + + # Output of the result if it is not None + if result is not None: + print(result) + return + else: + continue + + +# Start the program +if __name__ == "__main__": + main() diff --git a/HW2_Islamova/images/Dev_team.jpg b/HW2_Islamova/images/Dev_team.jpg new file mode 100644 index 0000000..4c2b9f9 Binary files /dev/null and b/HW2_Islamova/images/Dev_team.jpg differ diff --git a/HW2_Islamova/images/Dev_team1.jpg b/HW2_Islamova/images/Dev_team1.jpg new file mode 100644 index 0000000..f52e0cf Binary files /dev/null and b/HW2_Islamova/images/Dev_team1.jpg differ diff --git a/HW2_Islamova/images/snake.jpg b/HW2_Islamova/images/snake.jpg new file mode 100644 index 0000000..2733264 Binary files /dev/null and b/HW2_Islamova/images/snake.jpg differ