【发布时间】:2019-04-02 13:48:53
【问题描述】:
我正在尝试编写一个回合制游戏,其中有些事情需要不止一个回合才能发生。我发现在函数中放置一个while循环可以使需要一些轮流的动作起作用。这是我的测试:
#This function is supposed to 'work' after 3 turns
def action(current_turn):
while global_turn - current_turn != 3:
pass
test = "works"
test = "doesn't work"
game =True
global_turn = 0
while game:
global_turn += 1
print(f'\nThis is turn #{global_turn}\n')
user_input = input('Do [1]yes [2]no')
if user_input == '2':
pass
elif user_input == '1':
action(global_turn)
我认为这会一直打印“This is turn #{global_turn}”,即使我调用了该函数但它只是坐在那里。有什么方法可以让 while 循环继续进行,同时继续进行外部循环?
【问题讨论】:
标签: python-3.x while-loop