-
-
Notifications
You must be signed in to change notification settings - Fork 39
Update easyPythonpi.py #94
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
Conversation
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.
Hi @AndrewHUNGNguyen, can you pls assist with the issue that the test pipeline is failing. |
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.
Plz check I sended the pull request
With correct code.
Just now
…On Tue, Oct 22, 2024, 8:32 PM Aditya Sharma ***@***.***> wrote:
Hi @AndrewHUNGNguyen <https://github.com/AndrewHUNGNguyen>, can you pls
assist with the issue that the test pipeline is failing.
—
Reply to this email directly, view it on GitHub
<#94 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/A3IHY25IPRCXF3NTWXTQZXTZ4ZSJTAVCNFSM6AAAAABQMKG7RCVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDIMRZGUZTINRUGI>
.
You are receiving this because you authored the thread.Message ID:
***@***.***>
|
Hi
…On Tue, Oct 22, 2024, 9:04 PM Saketh Kotla ***@***.***> wrote:
Plz check I sended the pull request
With correct code.
Just now
On Tue, Oct 22, 2024, 8:32 PM Aditya Sharma ***@***.***>
wrote:
> Hi @AndrewHUNGNguyen <https://github.com/AndrewHUNGNguyen>, can you pls
> assist with the issue that the test pipeline is failing.
>
> —
> Reply to this email directly, view it on GitHub
> <#94 (comment)>,
> or unsubscribe
> <https://github.com/notifications/unsubscribe-auth/A3IHY25IPRCXF3NTWXTQZXTZ4ZSJTAVCNFSM6AAAAABQMKG7RCVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDIMRZGUZTINRUGI>
> .
> You are receiving this because you authored the thread.Message ID:
> ***@***.***>
>
|
hi plz check my new pull request |
pls check, the test cases are failing.... @kotla-saketh |
"""
A python module that helps you to calculate some of the most used
calculations.
Usage:
Download the file from GitHub and unzip it on your system.
To use this module, simply write the following in your code:
'from easypythonpi import *' and you are good to go!
~Happy Programming
"""
# Programmer-defined exceptions go here:
# Define exception for invalid binary strings
class InvalidBinaryException(Exception):
"""Raised when an invalid binary string is provided."""
pass
# Define exception for invalid Fibonacci numbers
class InvalidNumberFibException(Exception):
"""Raised when the Fibonacci number is invalid."""
def _init_(self, n, message="n is not valid, must be greater than or
equal to 1"):
self.n = n
self.message = message
super()._init_(self.message)
# Define exception for invalid measurements for shapes
class InvalidMeasurementShapeException(Exception):
"""Raised when invalid measurement values are provided for shapes."""
def _init_(self, message="Invalid measurement, must be greater than or
equal to 0"):
self.message = message
super()._init_(self.message)
# Functions for basic calculations
def add(num1, num2):
"""Add two numbers."""
return num1 + num2
def subtract(num1, num2):
"""Subtract two numbers."""
return num1 - num2
def multiply(num1, num2):
"""Multiply two numbers."""
return num1 * num2
def divide(num1, num2):
"""Divide two numbers with error handling for division by zero."""
try:
return num1 / num2
except ZeroDivisionError:
return "Error: Division by zero is not allowed."
# Binary string to decimal conversion
def binary_to_decimal(binary_str):
"""Convert binary string to decimal."""
try:
# Check if the binary string is valid
if not set(binary_str).issubset({'0', '1'}):
raise InvalidBinaryException(f"Invalid binary string:
{binary_str}")
return int(binary_str, 2)
except InvalidBinaryException as e:
return str(e)
# Fibonacci sequence generator
def fibonacci(n):
"""Generate Fibonacci sequence up to the nth number."""
if n < 1:
raise InvalidNumberFibException(n)
fib_sequence = [0, 1]
for i in range(2, n):
fib_sequence.append(fib_sequence[-1] + fib_sequence[-2])
return fib_sequence[:n]
# Shape area calculators
def calculate_circle_area(radius):
"""Calculate the area of a circle given the radius."""
if radius < 0:
raise InvalidMeasurementShapeException("Radius must be
non-negative.")
return 3.14159 * radius * radius
def calculate_rectangle_area(length, width):
"""Calculate the area of a rectangle."""
if length < 0 or width < 0:
raise InvalidMeasurementShapeException("Length and width must be
non-negative.")
return length * width
def calculate_square_area(side):
"""Calculate the area of a square."""
if side < 0:
raise InvalidMeasurementShapeException("Side must be non-negative.")
return side * side
# Example usage:
if _name_ == "_main_":
# Simple calculator usage
print("Please select operation -\n"
"1. Add\n"
"2. Subtract\n"
"3. Multiply\n"
"4. Divide\n")
try:
select = int(input("Select operations from 1, 2, 3, 4: "))
number_1 = float(input("Enter first number: "))
number_2 = float(input("Enter second number: "))
if select == 1:
print(f"{number_1} + {number_2} = {add(number_1, number_2)}")
elif select == 2:
print(f"{number_1} - {number_2} = {subtract(number_1,
number_2)}")
elif select == 3:
print(f"{number_1} * {number_2} = {multiply(number_1,
number_2)}")
elif select == 4:
result = divide(number_1, number_2)
print(f"{number_1} / {number_2} = {result}")
else:
print("Invalid input, please select a number between 1 and 4.")
except ValueError:
print("Error: Please enter valid numbers.")
… Message ID: ***@***.***>
|
pls check it working on my side
as according to comments and text i dont need to import any file also so it
has to run fine
…On Wed, Oct 23, 2024 at 12:08 PM Saketh Kotla ***@***.***> wrote:
"""
A python module that helps you to calculate some of the most used
calculations.
Usage:
Download the file from GitHub and unzip it on your system.
To use this module, simply write the following in your code:
'from easypythonpi import *' and you are good to go!
~Happy Programming
"""
# Programmer-defined exceptions go here:
# Define exception for invalid binary strings
class InvalidBinaryException(Exception):
"""Raised when an invalid binary string is provided."""
pass
# Define exception for invalid Fibonacci numbers
class InvalidNumberFibException(Exception):
"""Raised when the Fibonacci number is invalid."""
def _init_(self, n, message="n is not valid, must be greater than or
equal to 1"):
self.n = n
self.message = message
super()._init_(self.message)
# Define exception for invalid measurements for shapes
class InvalidMeasurementShapeException(Exception):
"""Raised when invalid measurement values are provided for shapes."""
def _init_(self, message="Invalid measurement, must be greater than or
equal to 0"):
self.message = message
super()._init_(self.message)
# Functions for basic calculations
def add(num1, num2):
"""Add two numbers."""
return num1 + num2
def subtract(num1, num2):
"""Subtract two numbers."""
return num1 - num2
def multiply(num1, num2):
"""Multiply two numbers."""
return num1 * num2
def divide(num1, num2):
"""Divide two numbers with error handling for division by zero."""
try:
return num1 / num2
except ZeroDivisionError:
return "Error: Division by zero is not allowed."
# Binary string to decimal conversion
def binary_to_decimal(binary_str):
"""Convert binary string to decimal."""
try:
# Check if the binary string is valid
if not set(binary_str).issubset({'0', '1'}):
raise InvalidBinaryException(f"Invalid binary string:
{binary_str}")
return int(binary_str, 2)
except InvalidBinaryException as e:
return str(e)
# Fibonacci sequence generator
def fibonacci(n):
"""Generate Fibonacci sequence up to the nth number."""
if n < 1:
raise InvalidNumberFibException(n)
fib_sequence = [0, 1]
for i in range(2, n):
fib_sequence.append(fib_sequence[-1] + fib_sequence[-2])
return fib_sequence[:n]
# Shape area calculators
def calculate_circle_area(radius):
"""Calculate the area of a circle given the radius."""
if radius < 0:
raise InvalidMeasurementShapeException("Radius must be
non-negative.")
return 3.14159 * radius * radius
def calculate_rectangle_area(length, width):
"""Calculate the area of a rectangle."""
if length < 0 or width < 0:
raise InvalidMeasurementShapeException("Length and width must be
non-negative.")
return length * width
def calculate_square_area(side):
"""Calculate the area of a square."""
if side < 0:
raise InvalidMeasurementShapeException("Side must be
non-negative.")
return side * side
# Example usage:
if _name_ == "_main_":
# Simple calculator usage
print("Please select operation -\n"
"1. Add\n"
"2. Subtract\n"
"3. Multiply\n"
"4. Divide\n")
try:
select = int(input("Select operations from 1, 2, 3, 4: "))
number_1 = float(input("Enter first number: "))
number_2 = float(input("Enter second number: "))
if select == 1:
print(f"{number_1} + {number_2} = {add(number_1, number_2)}")
elif select == 2:
print(f"{number_1} - {number_2} = {subtract(number_1,
number_2)}")
elif select == 3:
print(f"{number_1} * {number_2} = {multiply(number_1,
number_2)}")
elif select == 4:
result = divide(number_1, number_2)
print(f"{number_1} / {number_2} = {result}")
else:
print("Invalid input, please select a number between 1 and 4.")
except ValueError:
print("Error: Please enter valid numbers.")
> Message ID: ***@***.***>
>
|
class InvalidBinaryException(Exception):
"""Raised when an invalid binary string is provided."""
pass
# Define exception for invalid Fibonacci numbers
class InvalidNumberFibException(Exception):
"""Raised when the Fibonacci number is invalid."""
def __init__(self, n, message="n is not valid, must be greater than or
equal to 1"):
self.n = n
self.message = message
super().__init__(self.message)
# Define exception for invalid measurements for shapes
class InvalidMeasurementShapeException(Exception):
"""Raised when invalid measurement values are provided for shapes."""
def __init__(self, message="Invalid measurement, must be greater than
or equal to 0"):
self.message = message
super().__init__(self.message)
# Functions for basic calculations
def add(num1, num2):
"""Add two numbers."""
return num1 + num2
def subtract(num1, num2):
"""Subtract two numbers."""
return num1 - num2
def multiply(num1, num2):
"""Multiply two numbers."""
return num1 * num2
def divide(num1, num2):
"""Divide two numbers with error handling for division by zero."""
try:
return num1 / num2
except ZeroDivisionError:
return "Error: Division by zero is not allowed."
# Binary string to decimal conversion
def binary_to_decimal(binary_str):
"""Convert binary string to decimal."""
try:
# Check if the binary string is valid
if not set(binary_str).issubset({'0', '1'}):
raise InvalidBinaryException(f"Invalid binary string:
{binary_str}")
return int(binary_str, 2)
except InvalidBinaryException as e:
return str(e)
# Fibonacci sequence generator
def fibonacci(n):
"""Generate Fibonacci sequence up to the nth number."""
if n < 1:
raise InvalidNumberFibException(n)
fib_sequence = [0, 1]
for i in range(2, n):
fib_sequence.append(fib_sequence[-1] + fib_sequence[-2])
return fib_sequence[:n]
# Shape area calculators
def calculate_circle_area(radius):
"""Calculate the area of a circle given the radius."""
if radius < 0:
raise InvalidMeasurementShapeException("Radius must be
non-negative.")
return 3.14159 * radius * radius
def calculate_rectangle_area(length, width):
"""Calculate the area of a rectangle."""
if length < 0 or width < 0:
raise InvalidMeasurementShapeException("Length and width must be
non-negative.")
return length * width
def calculate_square_area(side):
"""Calculate the area of a square."""
if side < 0:
raise InvalidMeasurementShapeException("Side must be non-negative.")
return side * side
# Example usage:
if __name__ == "__main__":
# Simple calculator usage
print("Please select operation -\n"
"1. Add\n"
"2. Subtract\n"
"3. Multiply\n"
"4. Divide\n")
try:
select = int(input("Select operations from 1, 2, 3, 4: "))
number_1 = float(input("Enter first number: "))
number_2 = float(input("Enter second number: "))
if select == 1:
print(f"{number_1} + {number_2} = {add(number_1, number_2)}")
elif select == 2:
print(f"{number_1} - {number_2} = {subtract(number_1,
number_2)}")
elif select == 3:
print(f"{number_1} * {number_2} = {multiply(number_1,
number_2)}")
elif select == 4:
result = divide(number_1, number_2)
print(f"{number_1} / {number_2} = {result}")
else:
print("Invalid input, please select a number between 1 and 4.")
except ValueError:
print("Error: Please enter valid numbers.")
… Message ID: ***@***.***>
>>
>
|
can i remove above comments
…On Wed, Oct 23, 2024 at 12:13 PM Saketh Kotla ***@***.***> wrote:
class InvalidBinaryException(Exception):
"""Raised when an invalid binary string is provided."""
pass
# Define exception for invalid Fibonacci numbers
class InvalidNumberFibException(Exception):
"""Raised when the Fibonacci number is invalid."""
def __init__(self, n, message="n is not valid, must be greater than or
equal to 1"):
self.n = n
self.message = message
super().__init__(self.message)
# Define exception for invalid measurements for shapes
class InvalidMeasurementShapeException(Exception):
"""Raised when invalid measurement values are provided for shapes."""
def __init__(self, message="Invalid measurement, must be greater than
or equal to 0"):
self.message = message
super().__init__(self.message)
# Functions for basic calculations
def add(num1, num2):
"""Add two numbers."""
return num1 + num2
def subtract(num1, num2):
"""Subtract two numbers."""
return num1 - num2
def multiply(num1, num2):
"""Multiply two numbers."""
return num1 * num2
def divide(num1, num2):
"""Divide two numbers with error handling for division by zero."""
try:
return num1 / num2
except ZeroDivisionError:
return "Error: Division by zero is not allowed."
# Binary string to decimal conversion
def binary_to_decimal(binary_str):
"""Convert binary string to decimal."""
try:
# Check if the binary string is valid
if not set(binary_str).issubset({'0', '1'}):
raise InvalidBinaryException(f"Invalid binary string:
{binary_str}")
return int(binary_str, 2)
except InvalidBinaryException as e:
return str(e)
# Fibonacci sequence generator
def fibonacci(n):
"""Generate Fibonacci sequence up to the nth number."""
if n < 1:
raise InvalidNumberFibException(n)
fib_sequence = [0, 1]
for i in range(2, n):
fib_sequence.append(fib_sequence[-1] + fib_sequence[-2])
return fib_sequence[:n]
# Shape area calculators
def calculate_circle_area(radius):
"""Calculate the area of a circle given the radius."""
if radius < 0:
raise InvalidMeasurementShapeException("Radius must be
non-negative.")
return 3.14159 * radius * radius
def calculate_rectangle_area(length, width):
"""Calculate the area of a rectangle."""
if length < 0 or width < 0:
raise InvalidMeasurementShapeException("Length and width must be
non-negative.")
return length * width
def calculate_square_area(side):
"""Calculate the area of a square."""
if side < 0:
raise InvalidMeasurementShapeException("Side must be
non-negative.")
return side * side
# Example usage:
if __name__ == "__main__":
# Simple calculator usage
print("Please select operation -\n"
"1. Add\n"
"2. Subtract\n"
"3. Multiply\n"
"4. Divide\n")
try:
select = int(input("Select operations from 1, 2, 3, 4: "))
number_1 = float(input("Enter first number: "))
number_2 = float(input("Enter second number: "))
if select == 1:
print(f"{number_1} + {number_2} = {add(number_1, number_2)}")
elif select == 2:
print(f"{number_1} - {number_2} = {subtract(number_1,
number_2)}")
elif select == 3:
print(f"{number_1} * {number_2} = {multiply(number_1,
number_2)}")
elif select == 4:
result = divide(number_1, number_2)
print(f"{number_1} / {number_2} = {result}")
else:
print("Invalid input, please select a number between 1 and 4.")
except ValueError:
print("Error: Please enter valid numbers.")
> Message ID: ***@***.***>
>>>
>>
|
[image: image.png]
On Wed, Oct 23, 2024 at 12:14 PM Saketh Kotla ***@***.***>
wrote:
… can i remove above comments
On Wed, Oct 23, 2024 at 12:13 PM Saketh Kotla ***@***.***>
wrote:
> class InvalidBinaryException(Exception):
> """Raised when an invalid binary string is provided."""
> pass
>
> # Define exception for invalid Fibonacci numbers
> class InvalidNumberFibException(Exception):
> """Raised when the Fibonacci number is invalid."""
> def __init__(self, n, message="n is not valid, must be greater than
> or equal to 1"):
> self.n = n
> self.message = message
> super().__init__(self.message)
>
> # Define exception for invalid measurements for shapes
> class InvalidMeasurementShapeException(Exception):
> """Raised when invalid measurement values are provided for shapes."""
> def __init__(self, message="Invalid measurement, must be greater than
> or equal to 0"):
> self.message = message
> super().__init__(self.message)
>
> # Functions for basic calculations
>
> def add(num1, num2):
> """Add two numbers."""
> return num1 + num2
>
> def subtract(num1, num2):
> """Subtract two numbers."""
> return num1 - num2
>
> def multiply(num1, num2):
> """Multiply two numbers."""
> return num1 * num2
>
> def divide(num1, num2):
> """Divide two numbers with error handling for division by zero."""
> try:
> return num1 / num2
> except ZeroDivisionError:
> return "Error: Division by zero is not allowed."
>
> # Binary string to decimal conversion
> def binary_to_decimal(binary_str):
> """Convert binary string to decimal."""
> try:
> # Check if the binary string is valid
> if not set(binary_str).issubset({'0', '1'}):
> raise InvalidBinaryException(f"Invalid binary string:
> {binary_str}")
> return int(binary_str, 2)
> except InvalidBinaryException as e:
> return str(e)
>
> # Fibonacci sequence generator
> def fibonacci(n):
> """Generate Fibonacci sequence up to the nth number."""
> if n < 1:
> raise InvalidNumberFibException(n)
>
> fib_sequence = [0, 1]
> for i in range(2, n):
> fib_sequence.append(fib_sequence[-1] + fib_sequence[-2])
> return fib_sequence[:n]
>
> # Shape area calculators
>
> def calculate_circle_area(radius):
> """Calculate the area of a circle given the radius."""
> if radius < 0:
> raise InvalidMeasurementShapeException("Radius must be
> non-negative.")
> return 3.14159 * radius * radius
>
> def calculate_rectangle_area(length, width):
> """Calculate the area of a rectangle."""
> if length < 0 or width < 0:
> raise InvalidMeasurementShapeException("Length and width must be
> non-negative.")
> return length * width
>
> def calculate_square_area(side):
> """Calculate the area of a square."""
> if side < 0:
> raise InvalidMeasurementShapeException("Side must be
> non-negative.")
> return side * side
>
> # Example usage:
> if __name__ == "__main__":
> # Simple calculator usage
> print("Please select operation -\n"
> "1. Add\n"
> "2. Subtract\n"
> "3. Multiply\n"
> "4. Divide\n")
>
> try:
> select = int(input("Select operations from 1, 2, 3, 4: "))
> number_1 = float(input("Enter first number: "))
> number_2 = float(input("Enter second number: "))
>
> if select == 1:
> print(f"{number_1} + {number_2} = {add(number_1, number_2)}")
> elif select == 2:
> print(f"{number_1} - {number_2} = {subtract(number_1,
> number_2)}")
> elif select == 3:
> print(f"{number_1} * {number_2} = {multiply(number_1,
> number_2)}")
> elif select == 4:
> result = divide(number_1, number_2)
> print(f"{number_1} / {number_2} = {result}")
> else:
> print("Invalid input, please select a number between 1 and
> 4.")
>
> except ValueError:
> print("Error: Please enter valid numbers.")
>
>
>> Message ID: ***@***.***>
>>>>
>>>
|
Okay. Thanks. I'll take it from here and check it. Thanks for your contribution |
Hi buddy, recently we have fixed the checks issue, I would recommend you to pls take pull from main branch and merge it with you branch and then again push. This would resolve the pipeline issue. I'll then merge your code after review |
Ok, I will do that.
…On Sat, Oct 26, 2024, 1:12 AM Aditya Sharma ***@***.***> wrote:
Hi buddy, recently we have fixed the checks issue, I would recommend you
to pls take pull from main branch and merge it with you branch and then
again push. This would resolve the pipeline issue. I'll then merge your
code after review
—
Reply to this email directly, view it on GitHub
<#94 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/A3IHY2YHMGJJS7BIDOAFLCTZ5KNKZAVCNFSM6AAAAABQMKG7RCVHI2DSMVQWIX3LMV43OSLTON2WKQ3PNVWWK3TUHMZDIMZYGY3DKMRRGU>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
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.