Private archive copy · Unofficial site · Content copyright belongs to Runoob Tutorial and the original authors · View Original

Python Exercise Example 82

Python Exercise Example 82

Python 100 Examples Python 100 Examples

**Problem:** Convert octal to decimal

**Analysis:** None.

Example (Python 2.0+)

#!/usr/bin/python

-- coding: UTF-8 --

if

name

==

'

main

'

:

n

=

0

p

=

raw_input

(

'

input a octal number:

\n

'

)

for

i

in

range

(

len

(

p

)

)

:

n

=

n

8

ord

(

p

[

i

]

)

ord

(

'

0

'

)

print

n

The output of the above example is:


input a octal number:
122
82

Python 100 Examples Python 100 Examples