Python - 如何使程序回到第一个while循环,在第二个while循环中

时间:2016-07-01 06:06:43

标签: python loops

我试图回到第二个while循环中第一个while循环的开始。

loop_again = True # I want it to come back here
while loop_again:
    swap = "no" #LOOP 1
    while swap:
        import random #imports the random number function
        D1 = random.randrange(1,7)#sets random number from 1 to 6
        D2 = random.randrange(1,7)
        print (input("Press ENTER to roll the dice"))
        print (D1, D2)


        if D1 == 1 or D2 == 1:#checks if either dice is a 1
            total = (D1 + D2)
            P1_S = (P1_S - total)
            con = (input("Press ENTER to continue"))
            print ("Score: " +P1, P1_S)
        elif D1 and D2 == 1:
            P1_S = (P1_S + 25)
            con = (input("Press ENTER to continue"))
            print ("Score: " +P1, P1_S)
        elif D1 == D2:
            total = (D1 + D2)*2
            P1_S = (P1_S + total)
            con = (input("Press ENTER to continue"))
            print ("Score: " +P1, P1_S)
        else:
            total = (D1 + D2)
            P1_S = (P1_S + total)
            con = (input("Press ENTER to continue"))
            print ("Score: " +P1, P1_S)

        if D1 == 1 or D2 == 1:
            print ("Pass dice to " +P2,".")
            break
        else:
            swap = (input("Do you want to pass to the next player?"))
            if swap == "yes":
                print ("It is now "+P2,"'s turn")
                break
            elif swap == "no":
                print ("Press ENTER to continue")

swap = "no" #LOOP 2
while swap:
    import random #imports the random number function
    D1 = random.randrange(1,7)#sets random number from 1 to 6
    D2 = random.randrange(1,7)
    print (input("Press ENTER to roll the dice"))
    print (D1, D2)


    if D1 == 1 or D2 == 1:
        total = (D1 + D2)
        P2_S = (P2_S - total)
        con = (input("Press ENTER to continue"))
        print ("Score: " +P2, P2_S)
    elif D1 and D2 == 1:
        P2_S = (P2_S + 25)
        con = (input("Press ENTER to continue"))
        print ("Score: " +P2, P2_S)
    elif D1 == D2:
        total = (D1 + D2)*2
        P2_S = (P2_S + total)
        con = (input("Press ENTER to continue"))
        print ("Score: " +P2, P2_S)
    else:
        total = (D1 + D2)
        P2_S = (P2_S + total)
        con = (input("Press ENTER to continue"))
        print ("Score: " +P2, P2_S)

    if D1 == 1 or D2 == 1:
        if num_ps == "3" or num_ps == "4":
            print ("Pass dice to " +P3,".")
        elif num_ps != "3" or num_ps != "4":
            print ("It is now "+P1,"'s turn")# I want to go back from HERE

    else:
        swap = (input("Do you want to pass to the next player?"))
        if swap == "yes":
            if num_ps == "3" or num_ps == "4":
                print ("It is now "+P3,"'s turn")
                break
            elif num_ps != "3" or num_ps != "4":
                print("It is now "+P1,"'s turn") # and HERE
        elif swap == "no":
            print ("Press ENTER to continue")

事情是我尝试过继续使用,返回并计算并且他们没有工作。有没有办法做到这一点?

0 个答案:

没有答案