Skip to content
Closed
Changes from 5 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
19 changes: 19 additions & 0 deletions conversions/octal_to_binary.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
def octal_to_binary(octal)->int:

Choose a reason for hiding this comment

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

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

# Converting Octal to Decimal
decimal = 0
power = 0
while octal != 0:
decimal += (octal % 10) * pow(8, power)
octal //= 10
power += 1
# Converting Decimal to Binary
binary = 0
digit_place = 1
while decimal != 0:
binary += (decimal % 2) * digit_place
decimal //= 2
digit_place *= 10
return binary
octal_number = int(input("Enter octal number: "))
binary_number = octal_to_binary(octal_number)
print(f"The binary equivalent of {octal_number} is {binary_number}")