The program below will ask the user for an input phrase. The program should then use a "for" loop to iterate over the string, checking each character to see if it is a space (" "). If the character is a space, the loop should print out a message showing the index within the string where the space was found. There should be one line of output for each space found, plus a final "Scan complete" message after the loop ends.

Because we want to display the character index when a space is found, we initialize an index variable outside the loop to 0, representing the first character. This index should be increased by one at the end of each loop iteration to reflect the next character to be scanned.

The initial input, index initialization, and closing message statements are done for you. Where shown by the comments, take the following steps:

Create a "for" loop with the "in" keyword to iterate over each character in the phrase. Choose your own loop variable name to hold the current character.
Inside the loop:
Use an "if" statement to compare the current character to a space (" "). If it is equal, then print the message "Space at index X", where X is the current index value.
Increase the value in the index variable by 1, no matter what happens in the preceding "if" statement.
The following examples demonstrate the expected program output.

Please enter a phrase: The quick brown fox
Space at index 3
Space at index 9
Space at index 15
Scan complete
Please enter a phrase: nospace
Scan complete
Please enter a phrase: peas and carrots
Space at index 4
Space at index 8
Scan complete

# Solution:

phrase = input("Please enter a phrase: ")

index = 0

for char in phrase:
if char == " ":
print("Space at index", index)
index += 1

print("Scan complete")