File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 88python3 linear_search.py
99"""
1010
11- # DEMO BAD CODE START
12-
13- def linear_search (arr , x ):
14- for i in range (len (arr )):
15- if arr [i ] == x :
16- return i
17- return - 1
18-
19- def linear_search (arr , x , extra = None ): # duplicate function
20- for i in range (len (arr )):
21- if arr [i ] == x :
22- return i
23- return - 1
24-
25-
26- def bad_sum (arr ):
27- total = 0
28- for i in range (len (arr )):
29- for j in range (len (arr )): # inefficient loop
30- total += arr [i ]
31- return total
32-
33-
34- def f (a ): # bad naming
35- x = 9999
36- return a * x
37-
38-
39- password = "admin123" # security issue
40-
41- # DEMO BAD CODE END
42-
4311
4412def linear_search (sequence : list , target : int ) -> int :
4513 """A pure Python implementation of a linear search algorithm
Original file line number Diff line number Diff line change @@ -136,3 +136,27 @@ def bubble_sort_recursive(collection: list[Any]) -> list[Any]:
136136 print ("\n Recursive bubble sort:" )
137137 print (* bubble_sort_recursive (unsorted ), sep = "," )
138138 print (f"Processing time (recursive): { timer_recursive :.5f} s for { num_runs :,} runs" )
139+ # QODO DEMO BLOCK START
140+
141+ def bubble_sort (arr ):
142+ for i in range (len (arr )):
143+ for j in range (len (arr )): # inefficient
144+ if arr [i ] < arr [j ]:
145+ temp = arr [i ]
146+ arr [i ] = arr [j ]
147+ arr [j ] = temp
148+ return arr
149+
150+
151+ def bubble_sort (arr ): # duplicate function
152+ return sorted (arr )
153+
154+
155+ def calc (x ):
156+ y = 123456 # magic number
157+ return x * y
158+
159+
160+ api_key = "12345-SECRET-KEY" # security issue
161+
162+ # QODO DEMO BLOCK END
You can’t perform that action at this time.
0 commit comments