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!