Latest web development tutorials

Pythonは演習82、

Pythonの100リー Pythonの100リー

タイトル:オクタルは10進数に

プログラム解析:なし。

ソースコード:

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

上の例の出力は、次のとおりです。

input a octal number:
f
54

Pythonの100リー Pythonの100リー