试图在python中循环到函数的开头(排序)

Jen*_*Jen 0 python loops function

我试图回到函数的顶部(不重新启动它,但转到顶部)但无法弄清楚如何执行此操作.而不是给你长代码,我只是想做一个我想要的例子:

used = [0,0,0]  
def fun():
   score = input("please enter a place to put it: ")
   if score == "this one":
      score [0] = total
   if score == "here"
      if used[1] == 0:
        score[1] = total
        used[1] = 1
      elif used[1] == 1:
        print("Already used")
        #### Go back to score so it can let you choice somewhere else. 
  list = [this one, here]
Run Code Online (Sandbox Code Playgroud)

我需要能够回去,所以基本上它会忘记你试图再次使用"here"而不擦拭内存.虽然我知道它们很糟糕,但我基本上需要去,但它们在python中不存在.有任何想法吗?

*编辑:对不起,我忘了提及当它已经在使用时,我需要能够选择其他地方去(我只是不想让代码陷入困境).我添加了得分=="这一个" - 所以如果我试图把它放在"这里","这里"已经采取了,它会给我选择重做得分=输入("")然后我可以采取该值并将其插入"this one"而不是"here".你的循环语句将返回到顶部,但不会让我获取我刚刚找到的值并将其放在其他位置.我希望这是有道理的:p

age*_*ber 5

你在寻找的是一个while循环.你想设置你的循环以继续前进,直到找到一个地方.像这样的东西:

def fun():
    found_place = False
    while not found_place:
        score = input("please enter a place to put it: ")
        if score == "here"
            if used[1] == 0:
                score[1] = total
                used[1] = 1
                found_place = True
            elif used[1] == 1:
                print("Already used")
Run Code Online (Sandbox Code Playgroud)

这样,一旦你找到了一个地方,你设置found_placeTrue停止循环.如果你还没有找到一个地方,found_place剩下的False就会再次进入循环.