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
This Python module, easypythonpi.py, is designed to help with a variety of common calculations, including basic arithmetic operations, binary-to-decimal conversion, Fibonacci sequence generation, and shape area calculations. It is built with simplicity and ease of use in mind, making it ideal for both beginners and intermediate users. The module also includes custom exceptions to handle invalid inputs gracefully.
Copy file name to clipboardExpand all lines: easyPythonpi/easyPythonpi.py
+121-5Lines changed: 121 additions & 5 deletions
Original file line number
Diff line number
Diff line change
@@ -11,14 +11,130 @@
11
11
12
12
# define exception for invalid Binary Strings
13
13
14
+
# class InvalidBinaryException(Exception):
15
+
# pass
16
+
17
+
# class InvalidNumberFibException(Exception):
18
+
# def __init__(self, n, message="n is not valid, must be greater than or equal to 1"):
19
+
# self.n = n
20
+
# self.message = message
21
+
22
+
# class InvalidMeasurementShapeException(Exception):
23
+
# def __init__(self, message="invalid measurement, must be greater than or equal to 0"):
24
+
# self.message = message
25
+
26
+
"""This Python module, easypythonpi.py, is designed to help with a variety of common calculations, including basic arithmetic operations, binary-to-decimal conversion, Fibonacci sequence generation, and shape area calculations. It is built with simplicity and ease of use in mind, making it ideal for both beginners and intermediate users. The module also includes custom exceptions to handle invalid inputs gracefully."""
27
+
28
+
29
+
# Define exception for invalid binary strings
14
30
classInvalidBinaryException(Exception):
31
+
"""Raised when an invalid binary string is provided."""
15
32
pass
16
33
34
+
# Define exception for invalid Fibonacci numbers
17
35
classInvalidNumberFibException(Exception):
36
+
"""Raised when the Fibonacci number is invalid."""
18
37
def__init__(self, n, message="n is not valid, must be greater than or equal to 1"):
19
-
self.n=n
20
-
self.message=message
21
-
38
+
self.n=n
39
+
self.message=message
40
+
super().__init__(self.message)
41
+
42
+
# Define exception for invalid measurements for shapes
22
43
classInvalidMeasurementShapeException(Exception):
23
-
def__init__(self, message="invalid measurement, must be greater than or equal to 0"):
24
-
self.message=message
44
+
"""Raised when invalid measurement values are provided for shapes."""
45
+
def__init__(self, message="Invalid measurement, must be greater than or equal to 0"):
46
+
self.message=message
47
+
super().__init__(self.message)
48
+
49
+
# Functions for basic calculations
50
+
51
+
defadd(num1, num2):
52
+
"""Add two numbers."""
53
+
returnnum1+num2
54
+
55
+
defsubtract(num1, num2):
56
+
"""Subtract two numbers."""
57
+
returnnum1-num2
58
+
59
+
defmultiply(num1, num2):
60
+
"""Multiply two numbers."""
61
+
returnnum1*num2
62
+
63
+
defdivide(num1, num2):
64
+
"""Divide two numbers with error handling for division by zero."""
0 commit comments