Python Code Example: convert decimal to octal number

This code converts decimal to octal representation of a number. The function takes in an integer value x as an argument, and returns the octal representation of x.

The function uses the built-in oct function in Python to convert x to its octal representation, represented as a string with the prefix ‘0o’. The split method is used to remove the prefix ‘0o’, and the result is returned from the function.

For example, when this function is called with the argument 125, it returns the string ‘175’, which is the octal representation of 125. The print function is used to print the result.

def decToOct(x):
    return oct(x).split('o')[-1]