Python Program to Convert Decimal to Octal

« Previous Program Next Program »

Convert Decimal to Octal in Python

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

Python Programming Code to Convert Decimal to Octal

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

# Python Program - Convert Decimal to Octal

print("Enter 'x' for exit.");
dec = input("Enter number in Decimal Format: ");
if dec == 'x':
    decimal = int(dec);
    print(decimal,"in Octal =",oct(decimal));

Here is the sample run of the above Python program to illustrate how to convert decimal number to octal number:

decimal to octal python

As you can see that above one is the screenshot of initial output that will be displayed after running the above program, now you have to provide or supply any number in decimal form say 50 and press enter key to find out the same number in octal form as shown here in below sample output:

convert decimal to octal python

Below is the same program on python shell:

python convert decimal 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