[Tutor] "complete number" algorithm

Raymond Hettinger python@rcn.com
Sun, 23 Jun 2002 16:07:54 -0400


From: "Andrei Kulakov" <ak@silmarill.org>
> I'm working on a small algorithm that determines if a digit can be
> added at the end of one number and it could still be equal to or less
> than another number. 

> And if you type in 115 it should immediately pick #115, but if you type
> in 12, it should wait because you might mean 12 or may still be about
> to enter 120.


def final_num(num, max):
    """Test if num is final in max.
    
    12 is not final in 125
    12 is final in 8
    5 is not final in 83
    
    This function returns True only if you can't add anything to
    the num and still stay in bounds of max. 
    """
    return num*10 > max


Raymond Hettinger