Jump to content

New programmer needs a little guidance...

- - - - -

  • Please log in to reply
2 replies to this topic

#1
Reject

Reject

    Newbie

  • Members
  • PipPip
  • 10 posts
I sincerely apologize for my ignorance, this is my first crack at a programming language, so please try to keep the flaming to a minimum.

Here is what I am working with:

    


here = raw_input(">  ")

response = here.split()


if ("look" or "examine") and ("box" or "bag") in response:

    entrance_dun()


elif "move" and "right" in response:

     room_one()


elif ("left" or "niche") and "move" in response:

     entrance_niche()


else:

     commands(response)

     return entrance()


I think I may be missing something on the IF-Else conditions. If I take out the parenthesis, then anything entered returns the entrance_dun() response. With the parenthesis, I can get the combination: Look Box and Examine Box to work, but the bag side will not.

If I use something like this:

    


here = raw_input(">  ")

response = here.split()


if "look" or "examine" and "box" or "bag" in response:

    entrance_dun()


elif "move" and "right" in response:

     room_one()


elif ("left" or "niche") and "move" in response:

     entrance_niche()


else:

     commands(response)

     return entrance()


Anything I type, or do not type, defaults to the entrance_dun() event.

What am I missing?

Thank you in advance for the help!

#2
ZekeDragon

ZekeDragon

    Writes binary right handed and hex left handed

  • Moderators
  • 2,103 posts
The and and or keywords do not work the way you think they do.
if any(a in response for a in ["look", "examine"]) and any(a in response for a in ["box", "bag"]):

    entrance_dun()
That should work pretty well. It is a bit longer, but it will actually perform what is expected by you. Take a look at the provided link and see if you can reason why you got the results you did due to these keywords. It's logical, but not at all what you intended or thought it would do. :)
Wow I changed my sig!

#3
Reject

Reject

    Newbie

  • Members
  • PipPip
  • 10 posts
Worked perfectly.

So to get the logic down, we are basically comparing something what will always come back as false so that it checks both of the other conditions to see if they are true?




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users