Learn about Convert Decimal to Octal in Python in the below code example. Also, refer to the comments in the code snippet to get a detailed view of what’s actually happening.
Contents
Convert Decimal to Octal in Python
Specifically, we are converting a number having a base value of 10 to a number with a base value of 8. The number of digits used to represent a numeric value is determined by the base value of a number system. To represent any numeric value, the binary number system utilizes two digits 0 and 1, the octal number system uses eight digits 0-7, and the decimal number system uses ten digits 0-9.
Syntax:
oct(x)
Program:
# Python program to convert decimal to octal
# input
num = int(input('Enter any decimal number: '))
# print result
print('Octal value:', oct(num))
Output:
Enter any decimal number: 78
Octal value: 0o116
Hope above code works for you and Refer the below Related Codes to gain more insights. Happy coding and come back again.
Similar Code : Python program to convert decimal to octal using Recursion