Skip to content

Instantly share code, notes, and snippets.

LOG_FILE = "calculator_log.txt"
def log_result(operation, numbers, result):
"""Writes calculation results to a text file"""
with open(LOG_FILE, "a") as file:
file.write(f"{operation} {numbers} = {result}\n")
def add(nums):
def add(nums):
return sum(nums)
def subtract(nums):
result = nums[0]
for n in nums[1:]:
result -= n
return result
@namarzec
namarzec / gist:49d5731a6f3bceb9d0557e3adb4902c7
Created November 18, 2025 21:38
error_handling_assignment.py
# -----------------------------------------------------
# Error Handling Assignment - Python File
# All Exercises in One File
# -----------------------------------------------------
# Exercise 1: Divide By Zero Error
def safe_divide():
while True:
try:
num = float(input("Enter the numerator: "))