Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/loops/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Python 而循环永远循环_Python_Loops_While Loop_Forever - Fatal编程技术网

Python 而循环永远循环

Python 而循环永远循环,python,loops,while-loop,forever,Python,Loops,While Loop,Forever,所以,我正在通过浏览网页,并从这个论坛的用户那里得到一些帮助,来开发一个垃圾程序模拟器。我大部分时间都能完成。至少,我认为我对游戏的逻辑是正确的 上次我使用它时它正在运行,但我一定是在没有意识到的情况下更改了什么,因为现在while循环永远在运行。在这个程序中,没有用户干预,骰子永远在滚动 有人能看看代码是否有问题吗?我已经为此工作了好几个小时,但毫无进展 我再也不赌博了/ from Dice import PairOfDice print("Now Let's play with two di

所以,我正在通过浏览网页,并从这个论坛的用户那里得到一些帮助,来开发一个垃圾程序模拟器。我大部分时间都能完成。至少,我认为我对游戏的逻辑是正确的

上次我使用它时它正在运行,但我一定是在没有意识到的情况下更改了什么,因为现在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()
该区块:

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()
doubleDiceRoll从不更改,因此此循环将永远运行。在这个街区的尽头,但仍然在里面!,你应该这样做

    doubleDiceRoll = raw_input("Roll Again?") #Edit thanks to @Adam Smith

我认为你在以下情况下弄乱了你的缩进:

条件块的开始


这行下面的所有内容都在while循环之外,但可能应该在其中。

在脚本末尾,您有doubleDiceRoll=inputRoll?,但当doubleDiceRoll==时,它不在里面。没有任何更改条件,这始终是真实的IIRC doubleDiceRoll应该是对用户的提示,您想再次播放吗?我必须回顾一下他之前的帖子,我有公认的答案。编辑:是的,在他原来的while循环的末尾是doubleDiceRoll=raw\u再次输入Roll?行?。看起来整个东西都应该在while块中。好的,不管是哪种方式,doubleDiceRoll都需要更新。我更新了我的答案。谢谢比尔和莫尔斯特。我试图解决这个问题,但如果我将while语句改为false,代码就会停止。。。有什么想法吗?@user3462223你是如何打破while声明的?谢谢大家!!!正如你们所指出的,我不得不把这句话移到While块中去。我不知道昨晚为什么没赶上:/