Ask your own question, for FREE!
MIT 6.189 A Gentle Introduction to Programming Using Python (OCW) 7 Online
OpenStudy (anonymous):

Okay I am trying to do the Jack kack Lack exercise. I tried this: prefixes = "JKLMNOPQ" suffix = "ack" while prefixes == "O" or "Q": suffix = "uack" for letter in prefixes: print letter + suffix Anyone feel like offering a hint to make this work?

OpenStudy (rsmith6559):

Checking for the 'O' and 'Q' should be an if statement in the for loop.

OpenStudy (anonymous):

Okay thanks I will give it a go.

OpenStudy (anonymous):

Took me forever to realize Prefixes wasn't what I should have been using. I got it to work after many ouack puack quacks, but I sure it could be written more simply. Any pointers will be appreciated. prefixes = "JKLMNOPQ" suffix = "ack" for letter in prefixes: if letter == "O": suffix = "uack" print letter + suffix elif letter == "Q": suffix = "uack" print letter + suffix else: suffix = "ack" print letter + suffix

OpenStudy (anonymous):

This version has only one print statement and one test. def main(): prefixes = "JKLMNOPQ" suffix = "ack" for letter in prefixes: if letter in "OQ": letter += "u" print letter + suffix if __name__ == '__main__': main()

OpenStudy (anonymous):

rsmith6559 is right. The letters O and Q are different cases which may be managed in a if clause into the loop. i.e.: prefixes = "JKLMNOPQ" suffix = "ack" for letter in prefixes: if letter == "O" or letter == "Q": print letter + "u" + suffix else: print letter + suffix

OpenStudy (anonymous):

Mine came out the same as #dsabalete: prefixes = "JKLMNOPQ" letter = 0 suffix = "ack" for letter in prefixes: if letter == "O" or letter == "Q": print letter + "u" + suffix else: print letter + suffix

Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!
Can't find your answer? Make a FREE account and ask your own questions, OR help others and earn volunteer hours!

Join our real-time social learning platform and learn together with your friends!