Problem creating my own


I’m on the “Create your own” exercise, and I’ve run into what I believe is beyond my understanding.

author_favourite = [‘sushi’, ‘pizza’, ‘the blood of my enemies’]
user_favourite = []

print “What are your 3 favourite foods?:”

for food in range(3):
if user_favourite[food] == “poop”:
print “You’re disgusting.”

for a_food, u_food in zip(author_favourite, user_favourite):
if u_food == “poop”:
elif a_food == u_food:
print “Me too, I love %s.” % a_food
print “I didn’t expect you would enjoy %s.” % u_food

My code satisfies the requirements of the exercise, but I feel like there’s plenty to improve.

I’m wanting to display a single question and have the user input 3 individual elements. (A pipe dream?) A solution I came up with was to print a question first and leave the raw_input argument blank. However, I have a gut feeling that there’s a better way to do this.

My greatest frustration is how I’m handling the data. I would like the entire process to stop as soon as ‘poop’ is entered by the user. Currently if it gets “normal” inputs before ‘poop’, it will handle them before handling ‘poop’. Perhaps zip isn’t the best suited function? It’s likely just a Me issue as zip is simply iterating through the 2 lists.

Currently, the “elif a_food == u_food:” only executes if the indices are the same. This I believe to be the product of my improper use of zip as it pairs the elements.

To improve this I’m trying to figure out how to incorporate a list of profane words to be handled in the same manner as ‘poop’, but that’s for later. I’d also like to handle the finished product in a single line instead of multiple, but I know that’s a Me issue as that’s how I have written my code.

Any help is greatly appreciated!

thank you,


How do I compare the variables when using zip in a for loop?

On a technical note, you can let the user enter three words like a sentence.

user = input("Enter favorite... color season holiday ")

And the user could input

 green spring thanksgiving

The program would then,

user = user.split()

or if we want it to be immutable we could make it a tuple…

user = tuple(user.split())

Assuming the user input is in the same order as the prompts, we can then unpack the tuple,

color, season, holiday = user