From 5d4471d35a22ef267e91cedf2daae46aaa24a7b4 Mon Sep 17 00:00:00 2001 From: Sayan Bandyopadhyay Date: Sun, 7 Jan 2018 13:21:05 +0530 Subject: [PATCH] Update cyclesort.py Changing for Python 3 using exception handling for robust code --- sorts/cyclesort.py | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/sorts/cyclesort.py b/sorts/cyclesort.py index d6762b083..ee19a1ade 100644 --- a/sorts/cyclesort.py +++ b/sorts/cyclesort.py @@ -44,7 +44,13 @@ def cycle_sort(array): # Main Code starts here -user_input = input('Enter numbers separated by a comma:\n') +if __name__ == '__main__': + try: + raw_input # Python 2 + except NameError: + raw_input = input # Python 3 + +user_input = raw_input('Enter numbers separated by a comma:\n') unsorted = [int(item) for item in user_input.split(',')] n = len(unsorted) cycle_sort(unsorted)