Skip to content

Commit 3952cfa

Browse files
committedJul 30, 2023
Code Factorization
1 parent fc78e20 commit 3952cfa

File tree

1 file changed

+7
-13
lines changed

1 file changed

+7
-13
lines changed
 

‎linear_search.py

+7-13
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,11 @@
1-
list = []
21
num = int(input("Enter size of list: \t"))
3-
for n in range(num):
4-
numbers = int(input("Enter any number: \t"))
5-
list.append(numbers)
2+
list = [int(input("Enter any number: \t")) for _ in range(num)]
63

74
x = int(input("\nEnter number to search: \t"))
85

9-
found = False
10-
11-
for i in range(len(list)):
12-
if list[i] == x:
13-
found = True
14-
print("\n%d found at position %d" % (x, i))
15-
break
16-
if not found:
17-
print("\n%d is not in list" % x)
6+
for position, number in enumerate(list):
7+
if number == x:
8+
print(f"\n{x} found at position {position}")
9+
else:
10+
print(f"list: {list}")
11+
print(f"{x} is not in list")

0 commit comments

Comments
 (0)
Please sign in to comment.