Loops_ For your A


I`m unable to remove spaces and print my phrase.

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

Add your for loop

for char in phrase:
if char=='A' or char=='a':
print 'X',
print char

Don't delete this print statement!



print char

put a comma after char so your print statement does not create newline character!

to put exact phrase without any ' ' space between characters of phrase, You can use concatenation of string.


CC interpreter wants these spaces.
I just tested it without spaces printing the phrase after making 'A'/'a' 's to 'X' and it thrown an error.


why the last print statement is necessary??


The exercise needs it to be able to verify your code works correctly


but there is no use of that print statement practically right?:slight_smile:


well, a little bit, look at this two codes:

# code 1
print "hello",
print "world" 

# code 2
print "hello",
print "world"

it ensures after this print empty statement, new things are printed on a new line.

Its a little practical use

And yes, this also happens with the loop, go ahead and try it :wink:


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.