Program to convert decimal to octal in Python
In this python programming guide, we are going to learn
python program to convert decimal to octal using while loop
Python program to convert decimal to octal using while loop
The program to convert decimal to octal in python is as follows:
# Owner : TutorialsInhand Author : Devjeet Roy
result = list()
res = n % 8
n = n // 8
if __name__ == "__main__":
number = int(input("Enter a number: "))
ans = decimal_to_octal(number)
for i in ans:
The output of python program to convert decimal to octal using while loop is as follows:
PS C:\Users\DEVJEET\Desktop\tutorialsInHand> python code.py
Enter a number: 1223
Few important points about this program
1. First we ask the user to enter a number and we convert it to integer data type.
2. Then we call the decimal_to_octal function which divides the number by 8 and makes it the new number and store the remainders in a list. Finally, we return the list in reversed format.
3. In the main body, we have just printed the list elements.
Python code to convert decimal to octal snapshot:
Would you like to see your article here on tutorialsinhand.
program by tutorialsinhand.com
About the Author
Full Stack Web Developer & Data Science Enthusiast
Page Views :
Published Date :