The search is always canceled after the first hit. How can I correct this? I dont want to cancel.
Code:
from random import randrange
# the max number of values
NumberValue = 100
# an empty list for the values
ListOfNumberValue = []
found = False
search = 0
print("linear search")
runThrough = 1
while runThrough <= NumberValue:
ListOfNumberValue.append(randrange(1, 201))
runThrough = runThrough + 1
print("the values are: ")
for value in ListOfNumberValue:
print(value, end = " ")
print()
lookingFor = int(input("What to look for? "))
while search < NumberValue and found == False:
if ListOfNumberValue[search] == lookingFor:
found = True
else:
search = search + 1
if found == True:
print("Value", lookingFor, "is at position", search + 1)
else:
print("Value", lookingFor, "was not found.")
Comment