I am writing a program that is sort of a mini text adventure game however I seem to be experiencing some issues with my code. I am relatively new to programming as a whole so if you could explain your answers in-depth it would be of great assistance.
Here's the code:
#text_adventure_game.py
#python_ver == 3.5
verbs = ["get",
"put",
"drop",
"use",
"enter",
"leave",
"walk",
"search",
"attack",
"defend"]
nouns = ["journal",
"magnifier",
"glasses",
"knife",
"kite",
"table",
"chair",
"key"]
inventory = ""
user_input = input("What would you like to do?\n")
#checking if there are a set of two instructions
if(len(user_input.split())==2):
counter = 0
for token in user_input.split():
print(token)
print(counter)
if(counter==0):
if(token not in verbs):
print("I did not understand the verb entered.")
#removing square brackets and single quote marks from the array
print("Please use:", ", ".join(verbs))
counter = counter + 1
elif(token in verbs):
print("Recognized verb entered.")
counter = counter + 1
if(counter==1):
if(token not in nouns):
print("I did not understand the noun entered.")
print("Please use:", ", ".join(nouns))
counter = counter + 1
elif(token in nouns):
print("Recognized verb entered.")
counter = counter + 1
My problem is that it does not recognize the nouns I enter in the "nouns" array.
This is how it compiles:
>>>
What would you like to do?
get journal
get
0
Recognized verb entered.
I did not understand the noun entered.
Please use: journal, magnifier, glasses, knife, kite, table, chair, key
journal
2
If there are more efficient ways of doing things like this then that would also help.
Thanks.