A loop that never looks at the last item
Code review · Medium · §7.2, §7.3, §7.7 [Pair coding with AI] Asking for loops
This code tries to find the index of the post with the most likes and its number of likes. It runs without errors, but the answer is wrong. Fix just one place. Do not use max() or index().
Code to fix
likes = [12, 48, 7, 25, 63]
best = 0
for i in range(1, len(likes) - 1):
if likes[i] > likes[best]:
best = i
print(best, likes[best])Solve this problem in your browser
Python runs in your browser and checks your answer right away. Hints and the answer are on the problem page.