I need help with my PYTHON code Its supposed to accept any n
I need help with my PYTHON code. It\'s supposed to accept any number between 0 and 1000 and runs the program, but it only accepts the numbers in the highlited as you see in the picture. Can you please edit the code and make it work with all number between 0 and 1000. The code is in this link(you can edit it there and share the link here):
https://repl.it/EEEp/0
Please use comments to explain what you did. And use Python 3.5
Solution
There was just one mistake. In the first if and elif statements, the division does float arithmetic. However, you can force python to do integer division by using // instead of /. Or you can also do integer casting by writing int(number/10).
Hence, final code:
def numberSpelling(number):
    num2words = {1: \'One\', 2: \'Two\', 3: \'Three\', 4: \'Four\', 5: \'Five\', \\
                  6: \'Six\', 7: \'Seven\', 8: \'Eight\', 9: \'Nine\', 10: \'Ten\', \\
                  11: \'Eleven\', 12: \'Twelve\', 13: \'Thirteen\', 14: \'Fourteen\', \\
                  15: \'Fifteen\', 16: \'Sixteen\', 17: \'Seventeen\', 18: \'Eighteen\', \\
                  19: \'Nineteen\', 20: \'Twenty\', 30: \'Thirty\', 40: \'Forty\', \\
                  50: \'Fifty\', 60: \'Sixty\', 70: \'Seventy\', 80: \'Eighty\', \\
                  90: \'Ninety\', 0: \'Zero\'}
    output = \'\';
    if number >= 100:
        return num2words[number // 100] + \' hundred \' + numberSpelling(number % 100)
    elif number >= 20:
        return num2words[number // 10 * 10] + \' \' + numberSpelling(number % 10)
    elif number >= 1:
        return num2words[number]
    else:
        return \'zero\'
 def charCount(number):
    return len(numberSpelling(number)) - numberSpelling(number).count(\' \')
 number = int(input(\'Enter an integer between 0 - 1000: \'))
 if ((number) < 0 or (number) > 1000):
    print (\'Invalid range.\')
 else:
    while(charCount(number) != 4):
        print (numberSpelling(number), \' is \', charCount(number), \'.\')
        number = charCount(number)
    print (numberSpelling(number), \' is \', charCount(number), \'.\')
    print (\'four is magic.\')

