Skip to content

Commit

Permalink
Code Factorization
Browse files Browse the repository at this point in the history
  • Loading branch information
OfficialAhmed committed Jul 30, 2023
1 parent fc78e20 commit 3952cfa
Showing 1 changed file with 7 additions and 13 deletions.
20 changes: 7 additions & 13 deletions linear_search.py
Original file line number Diff line number Diff line change
@@ -1,17 +1,11 @@
list = []
num = int(input("Enter size of list: \t"))
for n in range(num):
numbers = int(input("Enter any number: \t"))
list.append(numbers)
list = [int(input("Enter any number: \t")) for _ in range(num)]

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

found = False

for i in range(len(list)):
if list[i] == x:
found = True
print("\n%d found at position %d" % (x, i))
break
if not found:
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 comments on commit 3952cfa

Please sign in to comment.