Skip to content

Commit 5d4471d

Browse files
authored
Update cyclesort.py
Changing for Python 3 using exception handling for robust code
1 parent 1f41a31 commit 5d4471d

File tree

1 file changed

+7
-1
lines changed

1 file changed

+7
-1
lines changed

sorts/cyclesort.py

+7-1
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,13 @@ def cycle_sort(array):
4444

4545

4646
# Main Code starts here
47-
user_input = input('Enter numbers separated by a comma:\n')
47+
if __name__ == '__main__':
48+
try:
49+
raw_input # Python 2
50+
except NameError:
51+
raw_input = input # Python 3
52+
53+
user_input = raw_input('Enter numbers separated by a comma:\n')
4854
unsorted = [int(item) for item in user_input.split(',')]
4955
n = len(unsorted)
5056
cycle_sort(unsorted)

0 commit comments

Comments
 (0)