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

_______________________________________________
Tutor maillist  -  [email protected]
http://mail.python.org/mailman/listinfo/tutor

Reply via email to