#1
  1. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2003
    Posts
    67
    Rep Power
    11

    Question Math/Number Theory?


    Is their a way to check, for example, in the last 2 digits in a number are 3. If so, how?
    Thanks.
    Before you criticize someone, walk a mile in their shoes, that way when you do criticize them, you're a mile away and you have their shoes!
  2. #2
  3. onCsdfeu
    Devshed Newbie (0 - 499 posts)

    Join Date
    Jul 2003
    Location
    Canada
    Posts
    100
    Rep Power
    11
    Well I can't think of a way to check that for ints. However, that'd be easy with strings.

    Say you have received an int called someint.
    Code:
    somestr = str(someint)
    if somestr[-2:] == '33': print 'Yay!'
    else: print 'Nay.'
    Of course, change the prints for anything to your liking.

    Hope this answered your question. There's a mathematical way to do it, but I'm not too sure about the efficiency of my method, so I'll stick to that string method.
  4. #3
  5. Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2003
    Posts
    67
    Rep Power
    11
    OK, I'll try that.
    Thanks.
  6. #4
  7. No Profile Picture
    Contributing User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Dec 2002
    Location
    Norwich, UK
    Posts
    53
    Rep Power
    12
    The simplest way to check an integer is to use the modulus operator (%).

    eg.
    Code:
    x = 45233
    if x % 100 == 33: print 'yep'

IMN logo majestic logo threadwatch logo seochat tools logo