ok so i was recently playing a game called ZORK a lot of older people will know what that is if you dont its a text based rpg that is realy addicting and amuseing so i wanted to attempt to figure out how they could have done something like this, so im getting there slowly but surely

well here is what i have so far and what its doing that i dont like.

items = ['crate', 'rock']
lookwords = ['look', 'examine']

input1 = raw_input(":")
i inputted 'look in the crate'

for word in item:
    for word2 in lookwords:
        if word and word2 in input1:
             print 'you look in the crate and find a map!'
        else:
             print 'sory you yoused a word i didnt understand'

so what it does is print out both outputs 2 times so its like
you look in the crate and find a map!
sory you yoused a word i didnt understand
you look in the crate and find a map!
sory you yoused a word i didnt understand

and i only want it to print one or the other

all help is greatly appreatated

First off, you have fallen for a trick almost everyone does when they start to learn programming. We find it in this line:

if word and word2 in input1:

That looks okay right? well unfortunately its not doing what you think. What the program does is it looks. Is there word? yes, there is a variable called word and yes there is something in it. This will therefore always be true.

Next it looks at the word2 in input1. The program checks if word2 is in input1. So you will find that it is every second time. This therefore showing why you are getting the answers the same twice :P Soo how do you fix it?

if word in input1 and word2 in input1:

Now this is your output:

>>>
:look in the crate
you look in the crate and find a map!
sory you yoused a word i didnt understand
sory you yoused a word i didnt understand
sory you yoused a word i didnt understand
>>>

So now you just have to work on not saying it four times.. Ill leave that up to you for now :)

Hope that helps

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.