Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

? #2

Open
TIMBER2024 opened this issue Oct 26, 2024 · 0 comments
Open

? #2

TIMBER2024 opened this issue Oct 26, 2024 · 0 comments

Comments

@TIMBER2024
Copy link
Owner

import logging
import pdb # Python debugger

Configure logging

logging.basicConfig(filename='app.log', level=logging.DEBUG, format='%(asctime)s - %(levelname)s - %(message)s')

def divide_numbers(a, b):
"""
Divide two numbers and return the result.

Args:
a (float): The numerator
b (float): The denominator

Returns:
float: The result of a / b

Raises:
ZeroDivisionError: If b is zero
"""
logging.debug(f"divide_numbers called with a={a}, b={b}")

# Potential breakpoint for interactive debugging
# pdb.set_trace()

try:
    result = a / b
    logging.info(f"Division successful. Result: {result}")
    return result
except ZeroDivisionError:
    logging.error("Attempted division by zero")
    raise
except Exception as e:
    logging.error(f"An unexpected error occurred: {e}")
    raise

def main():
logging.info("Starting the main function")

# Example usage
while True:
    try:
        num1 = float(input("Enter first number: "))
        num2 = float(input("Enter second number: "))
        result = divide_numbers(num1, num2)
        print(f"The result is: {result}")
    except ValueError:
        logging.warning("Invalid input, please enter numbers only")
        print("Please enter valid numbers.")
    except ZeroDivisionError:
        print("Cannot divide by zero!")
    except Exception as e:
        print(f"An error occurred: {e}")
    
    # Ask if the user wants to continue
    continue_operation = input("Do you want to perform another operation? (y/n): ")
    if continue_operation.lower() != 'y':
        break

logging.info("Exiting the main function")

if name == "main":
main()

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant