This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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): |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| def add(nums): | |
| return sum(nums) | |
| def subtract(nums): | |
| result = nums[0] | |
| for n in nums[1:]: | |
| result -= n | |
| return result |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # ----------------------------------------------------- | |
| # 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: ")) |