python - Exiting a function using only basic programming -
i working on assignment, , need exit function if value returns true. it's go fish game (you have been great far!) , i'm trying figure out how exit function.
def targetplayer(player_number, phands,sdeck): """user inputs player choosing target player, returns target players number""" gameoverhands = gameoverhands(phands) if gameoverhands == true: **missing code here** return gameoverhands else: showmessage("turn: player " + str(player_number) + ", it's turn. ") if player_number == 0: ask = raw_input("who want ask? (1-3) ") while not ask.isdigit() or ask not in "123": etc .... return other_values
i guess thing ask can have different return statements return value if if statement executed? gameoverhands saying have no cards in hand , game over, need somehow jump directly final function in game, whereas else statement (hopefully) execute rest of code repeatedly until gameover occurs. possible basic programming? input fantastic
it's have 1 single return
statement in python (as other languages), can have other ones also. it's making code readable possible.
here sample 1 final return in end:
def targetplayer(player_number, phands,sdeck): """user inputs player choosing target player, returns target players number""" result = gameoverhands(phands) if gameoverhands == true: **missing code here** result = gameoverhands else: showmessage("turn: player " + str(player_number) + ", it's turn. ") if player_number == 0: ask = raw_input("who want ask? (1-3) ") while not ask.isdigit() or ask not in "123": etc .... result = "thisnthat" return result
this re-defines "inner" function:
def outerfunc(cond): def inner1(): print('inner1') def inner2(): print('inner2') if cond: chosenfunc = inner1 else: chosenfunc = inner2 chosenfunc() outerfunc(true) outerfunc(false)
Comments
Post a Comment