Python Exercise Example 85
**Problem:** Input an odd number, then determine the minimum number of 9s such that dividing by that number gives 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
'
%d nines can be divided evenly by %d: %d
'
%
(
c9
,
zi
,
sum
)
r
=
sum
/
zi
'
%d / %d = %d
'
%
(
sum
,
zi
,
r
)
The output of the above example is:
Enter a number:
13
6 个 9 可以被 13 整除 : 999999
999999 / 13 = 76923
Python 100 Examples