You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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()
The text was updated successfully, but these errors were encountered:
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.
def main():
logging.info("Starting the main function")
if name == "main":
main()
The text was updated successfully, but these errors were encountered: