Why won't values between 100 and 1000 work when playing Four is Magic, excluding values by 100
<p>Everything works besides values between 100 and 999, except values divisible by 100 work.</p>

<p>The game is as follows:</p>

<p>Four is magic. Write a Python program (called q3.py) that given an integer from 0 to 1000 does the â4 is magicâ transformation. The steps are as follows:</p>

<ol>
<li>Convert the integer n into English and count the number of letters (i.e. 21 is âtwenty oneâ and consists of 9 letters, 102 is âone hundred twoâ and consists of 13 letters, 1000 is âone thousandâ and consists of 11 letters).</li>
<li><p>Let <code>nlen</code> be the length of the English word equivalent for the integer n.</p>

<p>a. If <code>nlen</code> is 4, output âfour is magic.â Then, terminate the transformation process.</p>

<p>b. Otherwise output â is <code>nlen</code>.â Repeat
step (a), where the integer n is set to <code>nlen</code>.</p></li>
</ol>

<p>Suppose the user inputs the integer 26. Then, the transformation proceeds as follows.</p>

<ol>
<li>26 is 9. , where twenty six is the 9-letter English word equivalent of 26.</li>
<li>9 is 4. , where nine is the 4-letter English word equivalent of 9.</li>
<li>4 is magic.</li>
</ol>

<p>&nbsp;</p>

<pre><code>def convert(number_str):

    # Enter your code here.
    count = 0
    index = 0
    x = ['zero','one','two','three','four','five','six','seven','eight','nine','ten','eleven','twelve','thirteen','fourteen','fifteen','sixteen','seventeen','eighteen','nineteen']
    y = ['zero','ten','twenty','thirty','forty','fifty','sixty','seventy','eighty','ninety']

    while (number_str != '4'):
        if 0 &lt;= int(number_str) &lt;= 19:
            a = len(x[int(number_str)])
            print(x[int(number_str)],'is',a)
            number_str = str(a)
        elif 20 &lt;= int(number_str) &lt;= 99:
            if number_str[1] == "0":
                a = len(y[int(number_str[0])])
                print(y[int(number_str[0])],'is',a)
                number_str = str(a)
            else:
                a = len(y[int(number_str[0])]) + len(x[int(number_str[1])])
                print(y[int(number_str[0])] + ' ' + x[int(number_str[1])],'is',a)
                number_str = a
        elif 100 &lt;= int(number_str) &lt;= 999:
            rem = int(number_str) % 100
            div = int(number_str) // 100
            if rem == 0:
                a = len(x[div]) + 7
                print(x[div] + ' hundred is',a)
                number_str = str(a)
            else:
                if (number_str[1] == '0'):
                    a = len(x[div]) + 7 + len(convert(str(rem)))
                    print(x[div] + ' hundred ' + convert(str(rem)) + ' is '+ str(a))
                    number_str = str(a)
                elif (number_str[1] != '0'):
                    a = len(x[div]) + 6 + len(convert(str(rem)))
                    print(x[div] + ' hundred ' + convert(str(rem)) + ' is '+ str(a))
                    number_str = str(a)
        elif number_str == '1000':
            a = 11
            print('one thousand is '+ str(a))
            number_str = str(a)
    return 'four is magic'

def main():
    ''' The program driver. '''

    user_input = input('&gt; ')
    while  user_input != 'quit':
        print(convert(user_input))
        user_input = input('&gt; ')


main()
</code></pre>

<p>My question is what is wrong with this area:</p>

<pre><code>else:
            if (number_str[1] == '0'):
                a = len(x[div]) + 7 + len(convert(str(rem)))
                print(x[div] + ' hundred ' + convert(str(rem)) + ' is '+ str(a))
                number_str = str(a)
            elif (number_str[1] != '0'):
                a = len(x[div]) + 6 + len(convert(str(rem)))
                print(x[div] + ' hundred ' + convert(str(rem)) + ' is '+ str(a))
                number_str = str(a)
</code></pre>

<pre><code>def convert(number_str):

    # Enter your code here.
    count = 0
    index = 0
    x = ['zero','one','two','three','four','five','six','seven','eight','nine','ten','eleven','twelve','thirteen','fourteen','fifteen','sixteen','seventeen','eighteen','nineteen']
    y = ['zero','ten','twenty','thirty','forty','fifty','sixty','seventy','eighty','ninety']

    while (number_str != '4'):
        if 0 &lt;= int(number_str) &lt;= 19:
            a = len(x[int(number_str)])
            print(x[int(number_str)],'is',a)
            number_str = str(a)
        elif 20 &lt;= int(number_str) &lt;= 99:
            if number_str[1] == "0":
                a = len(y[int(number_str[0])])
                print(y[int(number_str[0])],'is',a)
                number_str = str(a)
            else:
                a = len(y[int(number_str[0])]) + len(x[int(number_str[1])])
                print(y[int(number_str[0])] + ' ' + x[int(number_str[1])],'is',a)
                number_str = a
        elif 100 &lt;= int(number_str) &lt;= 999:
            rem = int(number_str) % 100
            div = int(number_str) // 100 
            print(div)
            if rem == 0:
                a = len(x[div]) + 7
                print(x[div] + ' hundred is',a)
                number_str = str(a)
            else:
                if (number_str[1] == '0'):
                    a = len(x[div]) + 7 + len(str(x[rem]))
                    print(x[div] + ' hundred ' + str(x[rem]) + ' is '+ str(a)) # error was here
                    number_str = str(a)
                elif (number_str[1] != '0'):
                    a = len(x[div]) + 6 + len(str(x[rem]))
                    print(x[div] + ' hundred ' + str(x[rem]) + ' is '+ str(a)) # error was here
                    number_str = str(a)
        elif number_str == '1000':
            a = 11
            print('one thousand is '+ str(a))
            number_str = str(a)
    return 'four is magic'


def main():
    ''' The program driver. '''

    user_input = input('&gt; ')
    while  user_input != 'quit':
        print(convert(user_input))
        user_input = input('&gt; ')


main()
</code></pre>

<p>Where I commented <code>#error</code> you were doing recursion which was not what you wanted ( I think). But fixed it and it should work now. When you call recursive functions (calling the same function) it execute the newest call on the stack, returning the value it came back with, which isn't how your program worked. </p>

<p>Also I noticed you weren't calling <code>x[rem]</code> like you were suppose to for a look up on the spelling, fixed that too. </p>

<p>Next time please include desired output instead of making us fish for information. </p>

python python-3.x simulation