QUESTION 1:
INCORRECT
values = [‘A’, ‘D’, ‘X’, ‘Y’, ‘c’, ‘a’] limit = ‘Y’
found = False
while position < len(values) and found: if values[position] >= limit:
found = True
if found:
print(“Found at position: ” position)
else:
print(“Not found.”)
CORRECT
values = [‘A’, ‘D’, ‘X’, ‘Y’, ‘c’, ‘a’] limit = ‘Y’
position = 0
found = False
while position < len(values) and not found: if values[position] > limit:
found = True
else:
position = position + 1
if found:
print(“Found at position: “, position) else:
print(“Not found.”)
QUESTION 2:
INCORRECT
# NEED TO DEFINE THE POSITION VARIABLE
# SHOULD BE “NOT FOUND”
# SHOULD BE > RATHER THAN >=
# ELSE CONDITION TO AVOID INFINITE LOOP # MISSING A COMMA AFTER THE STRING
my_input = input(“Enter a word: “)
print(“The earliest value is: “, earliest_lexicographically(value))
def earliest_lexicographically(my_string):
for i in range(1, len(my_string) – 1): if my_string[i] < earliest:
earliest = my_string[i]
CORRECT
value = input("Enter a word: ")
def earliest_lexicographically(my_string): earliest = my_string[0]
for i in range(1, len(my_string)):
if my_string[i] < earliest: earliest = my_string[i]
return earliest
# VARIABLE NAME MUST MATCH ARGUMENT IN FUNCTION CALL
# MISSING THIS DECLARATION # SHOULD NOT BE -1
# MISSING RETURN STATEMENT
print("The earliest value is: ", earliest_lexicographically(value))
# MUST COME AFTER FUNCTION DECLARATION