Python Practice Example 85
Question:Input an odd number, then determine the minimum number of 9s that, when divided by this number, results in an integer.
Program analysis:999999 / 13 = 76923。
Program source code:
Example
#!/usr/bin/python
# -*- coding: UTF-8 -*-
if __name__ == '__main__':
zi = int(raw_input('Enter a number:\n'))
n1 = 1
c9 = 1
m9 = 9
sum = 9
while n1 != 0:
if sum % zi == 0:
n1 = 0
else:
m9 *= 10
sum += m9
c9 += 1
print '%d 9s can be divided by %d: %d' % (c9,zi,sum)
r = sum / zi
print '%d / %d = %d' % (sum,zi,r)
The output result of the above example is:
输入一个数字: 13 6 个 9 可以被 13 整除 : 999999 999999 / 13 = 76923Other extensions
Python 100 Examples