Latest web development tutorials

Python 練習實例82

Python 100例 Python 100例

題目:八進制轉換為十進制

程序分析:無。

程序源代碼:

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