I'll just ask for help on this one function but so far all my functions are having similar issues and I think it has to do with my if statements.
Here's the function:
def cosby_room():
print "You enter a dark room and there is someone sitting alone on a couch."
print "Oh. It's Bill Cosby. What do ya know?"
print "He offers you a drink..."
print "Do you stay or leave?"
choice = raw_input("> ")
if "run" or "flee" or "leave" or "dart" or "get out" in choice:
print "Phew! That was close."
start()
elif "stay" or "drink" in choice:
print "You take a sip."
print "Everything starts to get all confusing."
print "Bill whispers something in your ear..."
print "You pass out and wake up in a park with a strange ache in your butt."
game_over("At least it'll make for an interesting story.")
else:
cosby_room()
So as of now if I run this function, no matter how input for choice, it goes down the first 'if' branch. Even if I type "stay" or "leave" I go down the first branch. I'm not really sure why or what's going on.. Can anyone help me out with this one?
[edit] I do like the solution provided. Is there a way to simplify:
if "run" in choice or "flee" in choice or "leave" in choice or "dart" in choice or "get out" in choice:
[edit2]
Thanks for the help everyone! I think I have it figured out. Here's the updated code:
def cosby_room():
print "You enter a dark room and there is someone sitting alone on a couch."
print "Oh. It's Bill Cosby. What do ya know?"
print "He offers you a drink..."
print "Do you stay or leave?"
choice = raw_input("> ")
strings = ("run", "flee", "leave", "dart", "get out")
strings2 = ("stay", "drink")
for word in choice:
if any(word in choice for word in strings):
print "Phew! That was close."
start()
elif any(word in choice for word in strings2):
print "You take a sip."
print "Everything starts to get all confusing."
print "Bill whispers something in your ear..."
print "You pass out and wake up in a park with a strange ache in your butt."
game_over("At least it'll make for an interesting story.")
else:
cosby_room()
Now I just need to learn about 'any'