而循环循环永远Python

use*_*223 0 python loops while-loop forever

所以,我正在研究一个掷骰子程序模拟器,从浏览网页,以及来自这个论坛上的用户的一些帮助.我能够在大多数情况下完成它.至少,我认为我有正确的游戏逻辑.

它是我上次使用它时运行但是我必须在没有意识到它的情况下改变了一些东西,因为现在while循环正在运行.在该计划中,骰子在没有用户干预的情况下永远滚动.

有人可以看一看,看看代码是否有问题?我已经在这个工作了几个小时,没有在哪里.

我再也不会赌博了!:/

from Dice import PairOfDice
print("Now Let's play with two dice!")
#
def MainDouble():
    bdice = PairOfDice()
    doubleDiceRoll = ''
    global myPoint #declare global variable
    input("Press Enter to Roll the Dice once")

    while doubleDiceRoll == '': #Roll the dice (both die objects)
        bdice.toss()
        print ('The first die reads.. ' + str(bdice.getValue1()) + '\n')
        print ('The second die reads.. ' + str(bdice.getValue2()) + '\n')

        Val = bdice.getTotal()

##Beginning of conditional blocks##
    if Val == 7 or Val == 11:
        gamestatus = "WON"


    elif Val == 2 or Val == 3 or Val == 12:
        gamestatus = "LOST"

    if Val != 7 and bdice.getTotal() != 11 and Val != 2 and Val != 3 and Val != 12:
        gamestatus = "CONTINUE"
            #
        myPoint = Val
        print("The Point is now " + myPoint + "/n") #display the user's point value
        global pSum 
        pSum = 0


    #The point

    while gamestatus == "CONTINUE": #Checking the point
            global point   
            point = myPoint   
            pSum = MainDouble()

            if pSum == myPoint:
             gamestatus == "WON"
            elif pSum == 7:
             gamestatus = "LOST"
            if gamestatus == "WON":
             print("Winner!")
            else:
             print("Sorry, Seven out!")
            print ("Roll Again?")

    doubleDiceRoll = input("Roll Again?")  

MainDouble()
Run Code Online (Sandbox Code Playgroud)

wfl*_*nny 5

这个块:

while doubleDiceRoll == '': #Roll the dice (both die objects)
    bdice.toss()
    print ('The first die reads.. ' + str(bdice.getValue1()) + '\n')
    print ('The second die reads.. ' + str(bdice.getValue2()) + '\n')

    Val = bdice.getTotal()
Run Code Online (Sandbox Code Playgroud)

doubleDiceRoll永远不会改变'',所以这个循环将永远运行.在这个块结束时(但仍在其中!),你应该做类似的事情

    doubleDiceRoll = raw_input("Roll Again?") #Edit thanks to @Adam Smith
Run Code Online (Sandbox Code Playgroud)