Created
November 2, 2020 11:26
-
-
Save diversemix/01dfb9701c7c4981914cbe2db95ba1be to your computer and use it in GitHub Desktop.
Python to rotate a string
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
# Given a number write a function that finds all rotations of its digits. | |
# For example for 197 the output would be 197, 971, and 719. | |
# Rotation is first diget to the moved to the end | |
# Last diget moved to the start | |
num = 1973 | |
def rotate(num_str): | |
return num_str[-1] + num_str[0:-1] | |
num_str = str(num) | |
length = len(num_str) | |
for i in range(length): | |
print(num_str) | |
num_str = rotate(num_str) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment