Back to Practice Dashboard
Python BasicsEasy

Octal to Decimal conversion

Learn how to solve the 'Octal to Decimal conversion' problem. This detailed resource details brute force and optimized approaches.

Problem Statement

Easy

Write a function octal_to_decimal(octal_str) that takes a string representing an octal number (base-8, digits 0-7) and returns its decimal (base-10) integer equivalent.

Each digit in an octal number represents a power of 8, starting from the rightmost digit (8^0).

Constraints
  • 1 <= len(octal_str) <= 10
  • octal_str contains only digits '0' through '7'

Examples

Example 1
Input
octal_to_decimal('17')
Output
15
Explanation

1×8¹ + 7×8⁰ = 8 + 7 = 15.

Example 2
Input
octal_to_decimal('144')
Output
100
Explanation

1×8² + 4×8¹ + 4×8⁰ = 64 + 32 + 4 = 100.

Example 3
Input
octal_to_decimal('10')
Output
8
Explanation

1×8¹ + 0×8⁰ = 8.

Need a Hint?
Use simple arithmetic operators (like modulo `%`, division `//`), conditional checks, or loops to inspect number properties.
Edge Cases to Watch
  • Empty list or null input variables
  • Single item lists/arrays
  • Extremely large input bounds causing integer or stack overflow

Ready to Solve?

Open the problem in PyRun's browser-based Python editor. Your code runs fully offline — no server required.

Open in Editor