[Tutor] New to programming question

Ben Markwell benmarkwell at gmail.com
Tue Apr 12 18:56:25 CEST 2005


This is an exercise from "How to think like a Computer Scientist."


The following example shows how to use concatenation and a for 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 *Make Way for Ducklings*, the names of the ducklings are 
Jack, Kack, Lack, Mack, Nack, Ouack, Pack, and Quack. This loop outputs 
these names in order: 

prefixes = "JKLMNOPQ" 
suffix = "ack" 

for letter in prefixes: 
print letter + suffix 

The output of this program is: 

Jack 
Kack 
Lack 
Mack 
Nack 
Oack 
Pack 
Qack 

Of course, that's not quite right because "Ouack" and "Quack" are 
misspelled.*
*

*As an exercise, modify the program to fix this error.
*

==================================================
 
In trying to solve the problem I have come up with the following:
 
prefixes = 'JKLMNOPQ'
suffix = 'ack'
xsuffix = 'uack'


for letter in prefixes:
n = 0
if prefixes[n] == 'O' or 'Q':
print prefixes[n] + xsuffix
else:
print letter + suffix
 
--- I know it doesn't work, but want to know if I am on the right track. And 
what is the solution?
 
Thanks
 
Ben
**
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20050412/22355b63/attachment.htm


More information about the Tutor mailing list