6
AssignmentMultiple Choice

Creating a Game

Question 6 • SC-Fundamentals of Computing - Content Recovery - Design & Development

In your guessing game, you replaced dashes in blanks when the user guessed a correct letter by using a string slice. Which line of code will replace the character with an index of n with the guessed letter?

Answer
A
blanks = blanks[:n] + letter + blanks[n+1:]
B
blanks = blanks(:n) + letter + blanks(n+1:)
C
blanks = blanks[n] + letter + blanks[n + ]
D
blanks = blanks(n) + letter + blanks(n+1)

Explanation

Python string slices use square brackets, and the ending index is excluded. So `blanks[:n]` keeps the characters before index n, `letter` replaces the character at n, and `blanks[n+1:]` keeps the characters after it. This makes A, `blanks = blanks[:n] + letter + blanks[n+1:]`, the correct line.

AI-written and checked against the verified answer.