Skip to content

Commit 43bc11c

Browse files
committed
update script useing f-strings
1 parent a1e0c50 commit 43bc11c

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

binary_search/binary_search.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ def binary_search_while(sorted_lists, wanted_item):
3030
mid_index = (low_index + high_index) // 2 # py3中的整数除
3131
mid_item = sorted_lists[mid_index]
3232
if mid_item == wanted_item:
33-
print('It takes {0} times to find {1} in index {2}'.format(_count, wanted_item, mid_index))
33+
print(f'It takes {_count} times to find {wanted_item} in index {mid_index}')
3434
return mid_index
3535
elif mid_item < wanted_item: # 如果猜的值小于目的值,则在大端继续查找
3636
low_index = mid_index + 1
@@ -67,7 +67,7 @@ def binary_search_recurse(sorted_lists, wanted_item, low_index=0, high_index=Non
6767
elif mid_item > wanted_item: # 小端查找
6868
return binary_search_recurse(sorted_lists, wanted_item, low_index, mid_index - 1)
6969

70-
print('It takes {0} times to find {1} in index {2}'.format(count, wanted_item, mid_index))
70+
print(f'It takes {count} times to find {wanted_item} in index {mid_index}')
7171
return mid_index
7272

7373

0 commit comments

Comments
 (0)