QUESTION IMAGE
Question
- what will happen if a program fails to close a file after reading it?
nothing. closing a file does not really matter.
the file will be marked as busy and will be inaccessible until the program ends.
you must restart your computer before it is usable again
- what is wrong with this linear search?
i = 0
while my_listi != key and i < len(my_list):
i += 1
the second check should be > not <
the first check should be ++ not !=
the second check should be <= not <
the loop needs to check to see if we ran out of list items before checking to see if the item is equal to the key.
For question 4, when a program fails to close a file after reading it, the file is marked as busy and inaccessible until the program ends. Closing files is important in programming to free up resources. For question 5, in a proper linear - search loop, we need to first check if we have reached the end of the list (i.e., run out of list items) before checking if the current item is equal to the key. If we don't do this, we may access an out - of - bounds index if the key is not in the list.
Snap & solve any problem in the app
Get step-by-step solutions on Sovi AI
Photo-based solutions with guided steps
Explore more problems and detailed explanations
- The file will be marked as busy and will be inaccessible until the program ends.
- The loop needs to check to see if we ran out of list items before checking to see if the item is equal to the key.