Python 練習實例82

Python 100例 Python 100例

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

程式分析:無。

實例(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

以上實例輸出結果為:

input a octal number:
122
82

Python 100例 Python 100例