Skip to content

Commit 76ed0f8

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

File tree

5 files changed

+23
-23
lines changed

5 files changed

+23
-23
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/pancake_sort.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,5 @@ def pancake_sort(arr):
1313
cur -= 1
1414
return arr
1515

16-
print(pancake_sort([0,10,15,3,2,9,14,13]))
16+
if __name__ == '__main__':
17+
print(pancake_sort([0,10,15,3,2,9,14,13]))

sorts/topological_sort.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,6 @@ def topological_sort(start, visited, sort):
2828
# return sort
2929
return sort
3030

31-
32-
sort = topological_sort('a', [], [])
33-
print(sort)
31+
if __name__ == '__main__':
32+
sort = topological_sort('a', [], [])
33+
print(sort)

sorts/tree_sort.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,4 +42,5 @@ def tree_sort(arr):
4242
inorder(root,res)
4343
return res
4444

45-
print(tree_sort([10,1,3,2,9,14,13]))
45+
if __name__ == '__main__':
46+
print(tree_sort([10,1,3,2,9,14,13]))

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)