Advertisement
icallitvera

Reverse Number (0-999) Script

Oct 30th, 2013
123
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.69 KB | None | 0 0
  1. def reverse(number):
  2.     #only works for (inner number) SYMMETRICAL numbers
  3.     #for non symmetrical numbers you have to add decimals until it becomes symmetrical!!!
  4.     #eg 9998 --> 8999
  5.     #but 9898 --> 8899 (it fails)
  6.     diff = 1
  7.     val = int(number-int(str(number)[-1]))
  8.     print val
  9.     while(str(val)[0]!=str(val)[-1]):
  10.         val = val + 1
  11.     print "PRINT SYMMETRICAL NUMBER IN SET 0-9: "+str(val)
  12.     print "NUMBER OF 9's: "+str(int(len(str(number))-1))
  13.     #cheaty method to make it:
  14.     #   1 = 9
  15.     #   2 = 99
  16.     #   3 = 999
  17.     #using the python method of "multiplying strings" and then casting back to an integer
  18.     print -(-int("9"*(int(len(str(number))-1)))*(number-val)-number)
  19.    
  20.    
  21. if __name__ == "__main__":
  22.     reverse(1222)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement