Python Program to Convert Binary to Octal

« Previous Program Next Program »

Convert Binary to Octal in Python

To convert binary to octal number in python, you have to ask from user to enter a number in binary number system to convert that number into octal number system as shown in the program given below.

Python Programming Code to Convert Binary to Octal

Following python program ask from user to enter binary number to convert it into octal number:

# Python Program - Convert Binary to Octal

print("Enter 'x' for exit.");
binary = input("Enter any number in Binary Format: ");
if binary == 'x':
    temp = int(binary, 2);
    print(binary,"in Octal =",oct(temp));

Here is the sample run of the above Python program to demonstrate how to convert binary to octal number:

binary to octal python

Now enter any number in binary to see the same number in octal form after pressing enter key as shown here:

convert binary to octal python

Below is the same program on python shell:

python convert binary to octal

Same Program in Other Languages

You may also like to learn or practice the same program in other popular programming languages:

« Previous Program Next Program »


Quick Links
Signup - Login - Give Online Test