Ask your own question, for FREE!
MIT 6.189 A Gentle Introduction to Programming Using Python (OCW) 19 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!
Latest Questions
Mari103: How to pop out like a Jacc In the box
31 minutes ago 0 Replies 0 Medals
Breathless: Spooky witch but cute
7 hours ago 3 Replies 0 Medals
Arriyanalol: help
7 hours ago 10 Replies 2 Medals
Arriyanalol: @tinydinoUwU stop trying to find a argument u blad lil boy
1 day ago 5 Replies 4 Medals
Jaded012023: Please tell me what you all think of this song
10 hours ago 6 Replies 1 Medal
Arriyanalol: bro how
10 hours ago 2 Replies 3 Medals
Arriyanalol: cant wait for the new bluey movie in 2027
1 day ago 12 Replies 2 Medals
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!