brewersfan1976

swap_neighbouring_digits.py

Jul 22nd, 2016
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.27 KB | None | 0 0
  1. def swapNeighbouringDigits(n):
  2.  
  3.     string = str(n)
  4.     string_length = len(string)
  5.     new_string = ""
  6.     x = 0
  7.    
  8.     while (x < string_length):
  9.           new_string = new_string + string[x + 1] + string[x]
  10.           x = x + 2
  11.    
  12.     return int(new_string)
Advertisement
Add Comment
Please, Sign In to add comment