Loops_ For your A


#1

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',
else:
print char

Don't delete this print statement!

print


#2

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.


#4

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.


#6

why the last print statement is necessary??


#7

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


#8

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


#9

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

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

# code 2
print "hello",
print
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:


#11

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