How to Convert Octal to Decimal in Python


With this example, you can get to know the conversion between octal and decimal in Python.

Source Code


#! /usr/bin/env python3
# -*- coding: utf-8 -*-

n = 0
p = input('Please input a octal number: ')

for i in range(len(p)):
    n = n * 8 + ord(p[i]) - ord('0')

print('Converted decimal number:')
print(n)

Output:


Please input a octal number:  12
Converted decimal number:
10
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments
Advertisement