Skip to content

Adds calculator #10

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

Open
wants to merge 2 commits into
base: work-experience-main
Choose a base branch
from

Conversation

olliesilvester
Copy link
Owner

Addresses #7

@olliesilvester olliesilvester changed the base branch from main to work-experience-main July 10, 2024 09:13
class OddValueError(Exception):
pass

def calculate():
Copy link
Owner Author

@olliesilvester olliesilvester Jul 10, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Better with type hinting:
def calculator() -> None:

class OddValueError(Exception):
pass

def calculate():
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
def calculate():
def calculate() -> None:

elif total % 2 == 0:
raise OddValueError(f"Total {total} is an odd number")
finally:
print(f"Yor total is {total}")
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your instead of yor

Comment on lines +11 to +12
num1 = int(input("Input the first number: "))
num2 = int(input("Input the second number: "))
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These can be floats as well, no need to convert to ints

try:
num1 = int(input("Input the first number: "))
num2 = int(input("Input the second number: "))
total = num1 + num2
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If calculator errors on negative or odd numbers, we should do our checks on the inputs rather than on the total

total = num1 + num2
if total < 0:
raise NegativeValueError(f"Total {total} is less than zero")
elif total % 2 == 0:
Copy link
Owner Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
elif total % 2 == 0:
elif total % 2 != 0:

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant