I am creating a text based game in Python and need help with splat parameters. I have a function that tests if input is valid, and also allows you to access your inventory. I have two parameters, one that gets the input prompt, and one that is valid answers to that prompt. The answers is a splat parameter because you can have multiple answers to the prompt. Here is that function:
def input_checker(prompt, *answers):
user_input = raw_input(prompt).lower()
if user_input == "instructions":
print
instructions()
elif user_input == "i" or user_input == "inventory":
if len(inventory) == 0:
print "There is nothing in your inventory."
else:
print "Your inventory contains:", ", ".join(inventory)
else:
if user_input in answers:
return user_input
else:
while user_input not in answers:
user_input = raw_input("I'm sorry. I did not understand your answer. Consider rephrasing. " + prompt )
if user_input in answers:
return user_input
break
I have two lists that contain common answers to questions:
yes = ["yes", "y", "yup", "yep"]
no = ["no", "n", "nope"]
If I call the function like this:
pizza = input_checker("Do you like pizza? ", yes, no)
It will always perform the while loop that asks for the input again, but if I remove the 'yes' or 'no' so there is only answer list, it will work
How do I go about having two arguments? What did I do wrong?