12) Error that only prints X X


#1



https://www.codecademy.com/courses/python-beginner-en-cxMGf/1/4?curriculum_id=4f89dab3d788890003000096#


The code only prints X X and not the entire string with the a's replaced like it should


phrase = "A bird in the hand..."

# Add your for loop
for c in phrase:
    if c=="A" or c=="a":
        
        print "X",
else:
    print char,





#Don't delete this print statement!
print


#2

if you want to achieve what you are trying to achieve, i put else inside the for loop. At the same indent level as if


#3

thank you very much, would you mind telling me what the difference is on how you indent the statement because on a previous assignment that was how i had to submit it


#4

as you currently, else will only run if the for loop is false. If you put else at the same indent level, it will run each time the if statement is false.


#5

while/for-else is quite different from if-else

the else to a loop runs if the loop was not broken (break) out of

@codeingkicks else needs to be at the same indentation level as the if


#6

thank you, that cleared things up