A lot of those lines are redundant. All you need is something like this*:
def recipe():
"""Create a list to store the recipe ingredients."""
print "Enter 5 ingredients that could possibly go into a cake: "
ingredients = raw_input("> ").split()
print ingredients
if len(ingredients) == 5:
print "Thanks"
elif len(ingredients) > 5:
print "That's too much"
elif len(ingredients) < 5:
print "That's too little"
else:
print "There's something wrong!"
recipe()
The most important line here is this:
ingredients = raw_input("> ").split()
It basically does two things:
Gets the input with
raw_input
.Splits the input on spaces using
str.split
. The result will be a list of substrings (the ingredients).
Also, if you are wondering, I made the comment at the top of your function into a proper docstring.
*Note: I assumed that the ingredients would be separated by spaces. If however you want to have them separated by something different, such as a comma, then you can give str.split
a specific delimiter:
ingredients = raw_input("> ").split(",")