Write a function that input a positive integer n and return the number of n-digit positive integers that divisible by 17
<p>I am working on Sage. Write a function that input a positive integer n and return the number of n-digit positive integers that divisible by 17. Be sure to account for the case where n=1. Test your program with inputs n=1,2,5.</p>

<p>What I understand that, for example, if I input n=1, it means that I need to check all the number from 0-9 which is divisible by 17. If I input n=2, it means that I need to check all the number between 0-99 inclusive which is divisible by 17. </p>

<p>I would not come up with a general formula which compute the length of n then take the right range of the number which is divisible by 17. </p>

<pre><code>def positive(n):
for n in range(0, 10**n):
    if (n%17==0):
        print n,
</code></pre>

<p>The above code work with me, but it just print it the number which is divisible by 17. I was wondering how would I count them, so I would know how many numbers are divisible by 17. </p>

<p>How about using number theory to simplify the problem, and use</p>

<pre><code>def positive(n):
    return 10**n // 17 + 1
</code></pre>

<p>I believe Sage uses the caret rather than the double-asterisk for exponentiation, so you may instead use</p>

<pre><code>10^n // 17 + 1
</code></pre>

<p>The plus-one includes the value 0, which is of course divisible by 17. You can check this with a longer version,</p>

<pre><code>def positive(n):
    return len([x for x in range(10**n) if x % 17 == 0])
</code></pre>

python sage