Python Practice Example 82

Python 100例Python 100 Examples

Problem:Convert octal to decimal

Program 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例Python 100 Examples

Other extensions