简体   繁体   中英

Python stops at a print statement

while Winner == "":
    while First_Player_Turn == "Y":
        while rtd != "":
            try:
                rtd = input("{} press enter to roll the dice".format(First_Player))
                if rtd == "":
                    dice = random.randint(1, 6)
                    First_Player_Position = dice + First_Player_Position
                    steps_left = 50 - First_Player_Position
                    print("{} needs {} steps to finish".format(First_Player, steps_left))
                    if First_Player_Position >= 50:
                        Winner = "Y"
                    First_Player_Turn = "N"
                    Second_Player_Turn = "Y"
                    print("Test to see if this is printed - It is but not in wingide")
                    continue
             except:
                    print("Please press enter")                    
    while Second_Player_Turn == "Y":

I have tested this multiple times and I have found out that wingide doesn't show the Tested part but normal Python does. What I want to happen is when it has run through the First_Player_Turn loop to go to the Second_Player_Turn loop.

You do not show the initialisation of the string variables. Your program starts with the following:

while Winner == "":
    while First_Player_Turn == "Y":
        while rtd != "":
  • If Winner is initialised as "" , the outer loop will run.
  • If First_Player_Turn is initialised as "Y" , the middle loop will run.
  • If rtd is not initialised as "" , the inner loop will run.

Because you haven't shown the initialisation of all three variables, you're obviously relying on magic for them to start with exactly the right values. Because that is unlikely, odds on none of the loops will run.

我自己已经弄清楚了,rtd 与其他 rtd 冲突,很抱歉浪费您的时间。

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM