Break outside loop Python function other options -
i have code:
def playagain1(): print("would keep boxing or quit while ahead? (y/n)") playagain = input().lower() if(playagain.startswith('y') == false): print("whatever chicken.") break
i want break loop if playagain()
doesn't start y
. whenever try, error:
'break' outside loop
how write better make work?
as matt bryant's answer states, can't break outside loop can return function. add need return value function, main programme loop knows whether return start or quit:
def main(): while true: # main game code goes here if not playagain(): break def playagain(): print("would keep boxing or quit while ahead? (y/n)") response = input().lower() return response.startswith('y')
Comments
Post a Comment