Latest web development tutorials

Python incluye ejercicios 82

Python 100 Li Python 100 Li

Título: Octal a decimal

Análisis del programa: Ninguno.

Código fuente:

#!/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

La salida del ejemplo anterior es:

input a octal number:
f
54

Python 100 Li Python 100 Li