Skip to content
Advertisement

How to use Python to convert an octal to a decimal

I had this little homework assignment and I needed to convert decimal to octal and then octal to decimal. I did the first part and could not figure out the second to save my life. The first part went like this:

JavaScript

I read how to convert it here: Octal to Decimal, but I have no clue how to turn it into code.

Advertisement

Answer

From decimal to octal:

JavaScript

Octal to decimal

JavaScript

If you want to return octal as a string then you might want to wrap it in str.

Advertisement