Skip to content

Commit f869c62

Browse files
Putting 'user oriented code' inside main condition for having valid imports
1 parent 31362cb commit f869c62

File tree

2 files changed

+16
-18
lines changed

2 files changed

+16
-18
lines changed

sorts/cycle_sort.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -50,11 +50,11 @@ def cycle_sort(array):
5050
except NameError:
5151
raw_input = input # Python 3
5252

53-
user_input = raw_input('Enter numbers separated by a comma:\n')
54-
unsorted = [int(item) for item in user_input.split(',')]
55-
n = len(unsorted)
56-
cycle_sort(unsorted)
57-
58-
print("After sort : ")
59-
for i in range(0, n):
60-
print(unsorted[i], end=' ')
53+
user_input = raw_input('Enter numbers separated by a comma:\n')
54+
unsorted = [int(item) for item in user_input.split(',')]
55+
n = len(unsorted)
56+
cycle_sort(unsorted)
57+
58+
print("After sort : ")
59+
for i in range(0, n):
60+
print(unsorted[i], end=' ')

sorts/wiggle_sort.py

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,11 @@ def wiggle_sort(nums):
99
if (i % 2 == 1) == (nums[i-1] > nums[i]):
1010
nums[i-1], nums[i] = nums[i], nums[i-1]
1111

12-
13-
print("Enter the array elements:\n")
14-
array=list(map(int,input().split()))
15-
print("The unsorted array is:\n")
16-
print(array)
17-
wiggle_sort(array)
18-
print("Array after Wiggle sort:\n")
19-
print(array)
20-
21-
12+
if __name__ == '__main__':
13+
print("Enter the array elements:\n")
14+
array=list(map(int,input().split()))
15+
print("The unsorted array is:\n")
16+
print(array)
17+
wiggle_sort(array)
18+
print("Array after Wiggle sort:\n")
19+
print(array)

0 commit comments

Comments
 (0)