Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def reverse(number):
- #only works for (inner number) SYMMETRICAL numbers
- #for non symmetrical numbers you have to add decimals until it becomes symmetrical!!!
- #eg 9998 --> 8999
- #but 9898 --> 8899 (it fails)
- diff = 1
- val = int(number-int(str(number)[-1]))
- print val
- while(str(val)[0]!=str(val)[-1]):
- val = val + 1
- print "PRINT SYMMETRICAL NUMBER IN SET 0-9: "+str(val)
- print "NUMBER OF 9's: "+str(int(len(str(number))-1))
- #cheaty method to make it:
- # 1 = 9
- # 2 = 99
- # 3 = 999
- #using the python method of "multiplying strings" and then casting back to an integer
- print -(-int("9"*(int(len(str(number))-1)))*(number-val)-number)
- if __name__ == "__main__":
- reverse(1222)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement