""" Worksheet: substituting strings """ story = """ Once upon a time, deep in an ancient jungle, there lived a %(animal)s. This %(animal)s liked to eat %(food)s, but the jungle had very little %(food)s to offer. One day, an explorer found the %(animal)s and discovered it liked %(food)s. The explorer took the %(animal)s back to %(city)s, where it could eat as much %(food)s as it wanted. However, the %(animal)s became homesick, so the explorer brought it back to the jungle, leaving a large supply of %(food)s. The End """ thewords = ['animal', 'food', 'city'] userpicks = {} def tellstory(): """ loop through thewords and get user choices in a dictionary named userpicks, then substitute userpicks into the story """ for word in thewords: userpicks[word] = raw_input("Enter a value for %s: " % word) print story % userpicks