Skip to content

easypythonpi.py solution #95

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

Closed
wants to merge 4 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
78 changes: 63 additions & 15 deletions easyPythonpi/easyPythonpi.py
Original file line number Diff line number Diff line change
@@ -1,24 +1,72 @@

""" A python module that helps you to calculate some of the most used calculations.....
""" A Python module that helps you to calculate some of the most used calculations.....
usage--
Just download the file from git and unzip in ur system.
Just download the file from git and unzip it on your system.
And while using this module, just write as code-
'from easypythonpi import *' and u r good to go...
~Happy programming"""


# Programmer defined exceptions go here:

# define exception for invalid Binary Strings
'from easypythonpi import *' and you're good to go...
~Happy programming
"""

# Programmer-defined exceptions
class InvalidBinaryException(Exception):
"""Raised when an invalid binary string is provided."""
pass

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

self.n = n
self.message = message
super().__init__(self.message)

class InvalidMeasurementShapeException(Exception):
def __init__(self, message="invalid measurement, must be greater than or equal to 0"):
self.message = message
"""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)

# Function definitions
def add(x, y):
"""Return the sum of x and y."""
return x + y

def subtract(x, y):
"""Return the difference of x and y."""
return x - y

def multiply(x, y):
"""Return the product of x and y."""
return x * y

def divide(x, y):
"""Return the quotient of x and y, or an error message if dividing by zero."""
if y == 0:
return "Cannot divide by zero"
return x / y

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.")
Loading