By "accumulator", I assume you mean the pattern in which you continuously add to a previous string. This can be had with the operator +=
.
By "concatenation", I assume you mean the string operator +
.
By your own rules, you aren't allowed the %
operator.
You might do it this way:
song = '' # Accumulators need to start empty
for _ in range(3): # Don't really need the stanza variable
animal = raw_input("What animal? ")
animalSound = raw_input("What sound does a %s make? " %(animal))
song += "Old MacDonald had an errno. EIEIO\n"
song += "His farm had a " + animal + " EIEIO\n"
song += "His " + animal + "made a noise: " + animalSound + "\n"
print song
etc.
I believe this is what your assignment calls for, but realize that this would
not be considered "good" or "Pythonic" code. In particular, string accumulation
is inefficient -- prefer list comprehensions and str.join()
.