Download as txt, pdf, or txt
Download as txt, pdf, or txt
You are on page 1of 1

DECLARE myList : ARRAY[0:8] OF INTEGER

DECLARE upperBound : INTEGER


DECLARE lowerBound : INTEGER
DECLARE index : INTEGER
DECLARE item : INTEGER
DECLARE itemIndex : INTEGER
DECLARE found : BOOLEAN
myList[0] <- 27
myList[1] <- 19
myList[2] <- 36
myList[3] <- 42
myList[4] <- 16
myList[5] <- 89
myList[6] <- 21
myList[7] <- 16
myList[8] <- 55
upperBound ← 8
lowerBound ← 0
OUTPUT "Please enter item to be found"
INPUT item
found ← FALSE
index ← lowerBound
REPEAT
IF item = myList[index] THEN
found <- true
itemIndex <- index
ENDIF
index ← index + 1
UNTIL (found = TRUE) OR (index > upperBound)
IF found THEN
OUTPUT "Item found, index ", itemIndex
ELSE
OUTPUT "Item not found"
ENDIF

Python:

myList = [27,19,36,42,16,89,21,16,55]
item = int(input("Please enter item to be found"))
found = false
for i in range(len(myList)):
if myList[i] == item:
found = true
itemIndex = i
break
if found:
print("Item found, index " + itemIndex)
else:
print("Item not found")

You might also like