-
Notifications
You must be signed in to change notification settings - Fork 0
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
base: work-experience-main
Are you sure you want to change the base?
Adds calculator #10
Conversation
class OddValueError(Exception): | ||
pass | ||
|
||
def calculate(): |
There was a problem hiding this comment.
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(): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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}") |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Your instead of yor
num1 = int(input("Input the first number: ")) | ||
num2 = int(input("Input the second number: ")) |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
elif total % 2 == 0: | |
elif total % 2 != 0: |
Addresses #7