-
-
Notifications
You must be signed in to change notification settings - Fork 46.5k
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
Octal to Binary Convert #8949
Octal to Binary Convert #8949
Conversation
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.
Click here to look at the relevant links ⬇️
🔗 Relevant Links
Repository:
Python:
Automated review generated by algorithms-keeper. If there's any problem regarding this review, please open an issue about it.
algorithms-keeper
commands and options
algorithms-keeper actions can be triggered by commenting on this PR:
@algorithms-keeper review
to trigger the checks for only added pull request files@algorithms-keeper review-all
to trigger the checks for all the pull request files, including the modified files. As we cannot post review comments on lines not part of the diff, this command will post all the messages in one comment.NOTE: Commands are in beta and so this feature is restricted only to a member or owner of the organization.
conversions/octal_to_binary.py
Outdated
@@ -0,0 +1,28 @@ | |||
def octal_to_binary(octal_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.
Please provide return type hint for the function: octal_to_binary
. If the function does not return a value, please provide the type hint as: def function() -> None:
Please provide type hint for the parameter: octal_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.
check again
for more information, see https://pre-commit.ci
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.
You have used int()
and bin()
functions which are built-in functions in Python used for converting between different number bases.
In this repo, all function should be implemented from scratch without using built-in functions.
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.
As already stated, this implementation just uses built-in Python functions to do all the work of the conversion. Plus, we'd rather have an implementation that converts directly from octal to binary without resorting to converting to decimal first.
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.
Click here to look at the relevant links ⬇️
🔗 Relevant Links
Repository:
Python:
Automated review generated by algorithms-keeper. If there's any problem regarding this review, please open an issue about it.
algorithms-keeper
commands and options
algorithms-keeper actions can be triggered by commenting on this PR:
@algorithms-keeper review
to trigger the checks for only added pull request files@algorithms-keeper review-all
to trigger the checks for all the pull request files, including the modified files. As we cannot post review comments on lines not part of the diff, this command will post all the messages in one comment.NOTE: Commands are in beta and so this feature is restricted only to a member or owner of the organization.
conversions/octal_to_binary.py
Outdated
@@ -0,0 +1,29 @@ | |||
def octal_to_binary(octal_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.
Please provide return type hint for the function: octal_to_binary
. If the function does not return a value, please provide the type hint as: def function() -> None:
As there is no test file in this pull request nor any test function or class in the file conversions/octal_to_binary.py
, please provide doctest for the function octal_to_binary
Please provide type hint for the parameter: octal_number
for more information, see https://pre-commit.ci
Check! |
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.
Click here to look at the relevant links ⬇️
🔗 Relevant Links
Repository:
Python:
Automated review generated by algorithms-keeper. If there's any problem regarding this review, please open an issue about it.
algorithms-keeper
commands and options
algorithms-keeper actions can be triggered by commenting on this PR:
@algorithms-keeper review
to trigger the checks for only added pull request files@algorithms-keeper review-all
to trigger the checks for all the pull request files, including the modified files. As we cannot post review comments on lines not part of the diff, this command will post all the messages in one comment.NOTE: Commands are in beta and so this feature is restricted only to a member or owner of the organization.
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.
Click here to look at the relevant links ⬇️
🔗 Relevant Links
Repository:
Python:
Automated review generated by algorithms-keeper. If there's any problem regarding this review, please open an issue about it.
algorithms-keeper
commands and options
algorithms-keeper actions can be triggered by commenting on this PR:
@algorithms-keeper review
to trigger the checks for only added pull request files@algorithms-keeper review-all
to trigger the checks for all the pull request files, including the modified files. As we cannot post review comments on lines not part of the diff, this command will post all the messages in one comment.NOTE: Commands are in beta and so this feature is restricted only to a member or owner of the organization.
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.
Minor tweaks in the header docstring, but other than that LGTM
conversions/octal_to_binary.py
Outdated
reference for better understand | ||
|
||
URL: https://en.wikipedia.org/wiki/Binary_number | ||
URL: https://en.wikipedia.org/wiki/Octal |
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.
Formatting and grammar fixes
reference for better understand | |
URL: https://en.wikipedia.org/wiki/Binary_number | |
URL: https://en.wikipedia.org/wiki/Octal | |
References for better understanding: | |
https://en.wikipedia.org/wiki/Binary_number | |
https://en.wikipedia.org/wiki/Octal |
conversions/octal_to_binary.py
Outdated
binary_number = "" | ||
octal_digits = "01234567" | ||
|
||
""" | ||
ValueError: String to the function | ||
>>> oct_to_decimal("Av") | ||
Traceback (most recent call last): | ||
... | ||
ValueError: Non-octal value was passed to the function | ||
>>> oct_to_decimal("90") | ||
Traceback (most recent call last): | ||
... | ||
ValueError: Special Character was passed to the function | ||
>>> oct_to_decimal("#$") | ||
Traceback (most recent call last): | ||
... | ||
ValueError: Empty String was passed to the function | ||
>>> oct_to_decimal("") | ||
... | ||
ValueError: octal value was passed to the function | ||
>>> oct_to_decimal("17") | ||
001111 | ||
>>> oct_to_decimal("7") | ||
111 | ||
""" |
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.
binary_number = "" | |
octal_digits = "01234567" | |
""" | |
ValueError: String to the function | |
>>> oct_to_decimal("Av") | |
Traceback (most recent call last): | |
... | |
ValueError: Non-octal value was passed to the function | |
>>> oct_to_decimal("90") | |
Traceback (most recent call last): | |
... | |
ValueError: Special Character was passed to the function | |
>>> oct_to_decimal("#$") | |
Traceback (most recent call last): | |
... | |
ValueError: Empty String was passed to the function | |
>>> oct_to_decimal("") | |
... | |
ValueError: octal value was passed to the function | |
>>> oct_to_decimal("17") | |
001111 | |
>>> oct_to_decimal("7") | |
111 | |
""" | |
""" | |
ValueError: String to the function | |
>>> oct_to_decimal("Av") | |
Traceback (most recent call last): | |
... | |
ValueError: Non-octal value was passed to the function | |
>>> oct_to_decimal("90") | |
Traceback (most recent call last): | |
... | |
ValueError: Special Character was passed to the function | |
>>> oct_to_decimal("#$") | |
Traceback (most recent call last): | |
... | |
ValueError: Empty String was passed to the function | |
>>> oct_to_decimal("") | |
... | |
ValueError: octal value was passed to the function | |
>>> oct_to_decimal("17") | |
001111 | |
>>> oct_to_decimal("7") | |
111 | |
""" | |
binary_number = "" | |
octal_digits = "01234567" |
Just noticed that the docstring is in the wrong place—I don't think these tests even pass because the error messages are wrong
for more information, see https://pre-commit.ci
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.
Please fix your broken doctests—they're breaking because they're wrongly formatted and because your function never raises the right ValueError in each case. Refer to the documentation for the doctest library for more info.
conversions/octal_to_binary.py
Outdated
References for better understanding: | ||
https://en.wikipedia.org/wiki/Binary_number | ||
https://en.wikipedia.org/wiki/Octal | ||
|
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.
Please remove this empty line
I have completed all documents and test cases. |
It means the build experienced an error. See the build logs:
It was expecting to get |
conversions/octal_to_binary.py
Outdated
'111' | ||
""" | ||
if not octal_number: | ||
raise ValueError("Empty String was passed to the function") |
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.
raise ValueError("Empty String was passed to the function") | |
raise ValueError("Empty string was passed to the function") |
conversions/octal_to_binary.py
Outdated
for digit in octal_number: | ||
if not digit.isdigit(): | ||
raise ValueError("Special Character was passed to the function") | ||
|
||
if digit < "0" or digit > "7": | ||
raise ValueError("Non-octal value was passed to the function") | ||
|
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.
for digit in octal_number: | |
if not digit.isdigit(): | |
raise ValueError("Special Character was passed to the function") | |
if digit < "0" or digit > "7": | |
raise ValueError("Non-octal value was passed to the function") |
These checks are unnecessary because you're already checking each character in the for-loop
conversions/octal_to_binary.py
Outdated
octal_digits = "01234567" | ||
for digit in octal_number: | ||
if digit not in octal_digits: | ||
raise ValueError("Octal value was passed to the function") |
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.
raise ValueError("Octal value was passed to the function") | |
raise ValueError("Non-octal value was passed to the function") |
This error message is incorrect
conversions/octal_to_binary.py
Outdated
""" | ||
Convert an Octal number to Binary. | ||
|
||
ValueError: Non-octal value was passed to the function | ||
>>> octal_to_binary("Av") | ||
Traceback (most recent call last): | ||
... | ||
ValueError: Non-octal value was passed to the function | ||
|
||
ValueError: Special Character was passed to the function | ||
>>> octal_to_binary("@#") | ||
Traceback (most recent call last): | ||
... | ||
ValueError: Special Character was passed to the function | ||
|
||
ValueError: Empty String was passed to the function | ||
>>> octal_to_binary("") | ||
Traceback (most recent call last): | ||
... | ||
ValueError: Empty String was passed to the function | ||
|
||
ValueError: Octal value was passed to the function | ||
>>> octal_to_binary("17") | ||
'001111' | ||
|
||
ValueError: Octal value was passed to the function | ||
>>> octal_to_binary("7") | ||
'111' | ||
""" |
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.
""" | |
Convert an Octal number to Binary. | |
ValueError: Non-octal value was passed to the function | |
>>> octal_to_binary("Av") | |
Traceback (most recent call last): | |
... | |
ValueError: Non-octal value was passed to the function | |
ValueError: Special Character was passed to the function | |
>>> octal_to_binary("@#") | |
Traceback (most recent call last): | |
... | |
ValueError: Special Character was passed to the function | |
ValueError: Empty String was passed to the function | |
>>> octal_to_binary("") | |
Traceback (most recent call last): | |
... | |
ValueError: Empty String was passed to the function | |
ValueError: Octal value was passed to the function | |
>>> octal_to_binary("17") | |
'001111' | |
ValueError: Octal value was passed to the function | |
>>> octal_to_binary("7") | |
'111' | |
""" | |
""" | |
Convert an Octal number to Binary. | |
>>> octal_to_binary("17") | |
'001111' | |
>>> octal_to_binary("7") | |
'111' | |
>>> octal_to_binary("Av") | |
Traceback (most recent call last): | |
... | |
ValueError: Non-octal value was passed to the function | |
>>> octal_to_binary("@#") | |
Traceback (most recent call last): | |
... | |
ValueError: Non-octal value was passed to the function | |
>>> octal_to_binary("") | |
Traceback (most recent call last): | |
... | |
ValueError: Empty string was passed to the function | |
""" |
Place the most import doctests at the top (the ones that demonstrate correct output) and edge cases should come after those. Also, there's no need to describe the error when the doctests already shows the error messages.
I understand. I am saying that If I remove the Special character test case! |
My suggestions do not remove the special character test case. That doctest is still there. My point is that you had already handled special characters in your for-loop, so there's no need to handle it ahead of time before the for-loop. |
for more information, see https://pre-commit.ci
for more information, see https://pre-commit.ci
Hello, @tianyizheng02 Finally could you check? |
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.
Just some minor formatting issues, but other than that LGTM
* Octal to Binary Convert * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * mention return type * code scratch * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * mentioned return type * remove comment * added documention and some test cases * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * add another test case * fixes documention * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Documention and test cases added * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * documention problem solved * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * error in exit 1 * [pre-commit.ci] auto fixes from pre-commit.com hooks for more information, see https://pre-commit.ci * Apply suggestions from code review --------- Co-authored-by: BamaCharanChhandogi <b.c.chhandogi@gmailcom> Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com> Co-authored-by: Tianyi Zheng <tianyizheng02@gmail.com>
Describe your change:
Checklist: