We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent fc78e20 commit 3952cfaCopy full SHA for 3952cfa
linear_search.py
@@ -1,17 +1,11 @@
1
-list = []
2
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)
+list = [int(input("Enter any number: \t")) for _ in range(num)]
6
7
x = int(input("\nEnter number to search: \t"))
8
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)
+for position, number in enumerate(list):
+ if number == x:
+ print(f"\n{x} found at position {position}")
+else:
+ print(f"list: {list}")
+ print(f"{x} is not in list")
0 commit comments