from typing import List def bowlingScore(frames: List[int]) -> int: """Calculate the total score of a bowling game.""" scores: List[int] = [] next_frame = 0 for i in range(10): frame_score = 0 if frames[next_frame] == 10: frame_score += 10 if i < 10: frame_score += frames[next_frame + 1] if frames[i + 1] == 10: frame_score += frames[next_frame + 2] else: frame_score += frames[next_frame + 2] next_frame += 1 elif frames[next_frame] + frames[next_frame + 1] == 10: frame_score += 10 frame_score += frames[next_frame + 2] next_frame += 2 else: frame_score += frames[next_frame] + frames[next_frame + 1] next_frame += 2 scores.append(frame_score) return sum(scores) print("Testing bowlingScore()...", end="") assert bowlingScore([10] * 12) == 300 assert bowlingScore([7, 2, 8, 2, 10, 7, 1, 8, 2, 7, 3, 10, 10, 5, 4, 8, 2, 7]) == 162 assert bowlingScore([2, 6, 2, 6, 9, 1, 10, 10, 10, 5, 1, 4, 5, 9, 0, 8, 1]) == 140 assert ( bowlingScore([6, 4, 2, 7, 8, 1, 2, 4, 6, 3, 10, 6, 2, 1, 9, 6, 4, 10, 10, 10]) == 137 ) assert bowlingScore([8, 1, 5, 3, 4, 3, 0, 8, 9, 0, 8, 1, 3, 6, 1, 8, 5, 4, 7, 1]) == 85 # Finally, verify that the function is non-mutating L = [7, 2, 8, 2, 10, 7, 1, 8, 2, 7, 3, 10, 10, 5, 4, 8, 2, 7] bowlingScore(L) assert L == [7, 2, 8, 2, 10, 7, 1, 8, 2, 7, 3, 10, 10, 5, 4, 8, 2, 7] print("Passed!")