Wednesday, 15 June 2011

Calling next Function: Python -



Calling next Function: Python -

this question has reply here:

how test 1 variable against multiple values? 13 answers

i have function:

def abandoned_station(): print """ ..... """ next = raw_input(prompt) if next == "store room" or "store room" or "store room": store_room() elif next == "control room" or "control room" or "control room": control_room() elif next == "look" or "look": abandoned_station else: print "sorry, not understand command."

but when input 'control room' @ prompt, goes store_room function. if come in else, goes original abandoned_station function - doesn't doesn't understand.

have created loop here have missed?

thanks in advance.

if comparisons that:

if next == "store room" or "store room" or "store room":

what means is

if (next == "store room") or ("store room") or ("store room"):

that means, pythons dynamic nature evaluates boolean of string, true unless empty. have compare every clause next:

if (next == "store room") or (next == "store room") or (next == "store room"):

to quote python documentation:

in context of boolean operations, , when expressions used command flow statements, next values interpreted false: false, none, numeric 0 of types, , empty strings , containers (including strings, tuples, lists, dictionaries, sets , frozensets). other values interpreted true. (see nonzero() special method way alter this.)

source: python doc

python function

No comments:

Post a Comment