<p>This is an exercise from "How to think like a Computer Scientist."<br>
<br>
<br>
The following example shows how to use concatenation and a <span class="code"><span class="keyword">for</span></span> loop to generate an abecedarian series. "Abecedarian" refers
to a series or list in which the elements appear in alphabetical
order. For example, in Robert McCloskey's book <i>Make Way for
Ducklings</i>, the names of the ducklings are Jack, Kack, Lack, Mack,
Nack, Ouack, Pack, and Quack. This loop outputs these names in order:
</p>
<p><span class="code">prefixes = <span class="quote">"JKLMNOPQ"</span>
<br>suffix = <span class="quote">"ack"</span>
<br>
<br><span class="keyword">for</span> letter <span class="keyword">in</span> prefixes:
<br> <span class="keyword">print</span> letter + suffix
<br></span></p>
<p>
The output of this program is:
</p>
<p><span class="code">Jack
<br>Kack
<br>Lack
<br>Mack
<br>Nack
<br>Oack
<br>Pack
<br>Qack
<br></span></p>
<p>
Of course, that's not quite right because "Ouack" and
"Quack" are misspelled.<i><span style="font-style: italic;"><br>
</span></i></p>
<p><i><span style="font-style: italic;"></span>As an exercise, modify the program to fix this error.<br>
</i></p>
<p>==================================================<br>
</p>
<p>In trying to solve the problem I have come up with the following:<br>
</p>
<p>prefixes = 'JKLMNOPQ'<br>
suffix = 'ack'<br>
xsuffix = 'uack'<br>
<br>
<br>
for letter in prefixes:<br>
n = 0<br>
if prefixes[n] == 'O' or 'Q':<br>
print prefixes[n] + xsuffix<br>
else:<br>
print letter + suffix<br>
</p>
<p>--- I know it doesn't work, but want to know if I am on the right track. And what is the solution?<br>
</p>
<p>Thanks<br>
</p>
<p>Ben<br>
<i><span style="font-style: italic;"></span></i></p>
<blockquote>
</blockquote>