Created
January 4, 2016 18:35
-
-
Save MattyAyOh/bb352ea7b66495fad5d0 to your computer and use it in GitHub Desktop.
Reverse an integer in Python in place
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
inputNum = 1234 | |
reverseNum = 0 | |
while inputNum > 0: | |
reverseNum = (reverseNum*10) + (inputNum%10) | |
inputNum = inputNum/10 | |
print reverseNum |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Write a function that takes an integer, then reverses the digits in the integer, and returns that reversed integer
Example: 123 -> 321; 5034 -> 4305