代码不会循环通过正确的while循环。蟒蛇

时间:2016-06-17 00:18:41

标签: python while-loop

我试图让我的代码循环一段时间循环,但是它会循环错误的while循环。这是代码。

    curr_player = 1     #All the variables are set.
    curr_round = 0      
    points = [0,0]      
    curr_str = ''       
    round_over = True          

L82  while round_over: 
        round_over = False # Set round over to false.
        curr_round += 1 # Add a round to the current round
        print 'Round %s starting...' % curr_round # start the current round


        while True:
            print ''
            print 'Player 1: %s     Player 2: %s' % (points[0], points[1]) # Print the player's scores.
            print ''

  L93        while True:
                if len(curr_str) > 0: # If a letter was inputted inputed...
                    print ""
                    print (" "*5)+'Current String =  "%s"' % curr_str # Print to the user what the string currently is
                    print ""

                new_letter = str(raw_input('Player %s, Enter a letter: '  % curr_player)) # Ask the user for a new letter
                if new_letter > 1: # If the was a letter inputed
                    curr_str += new_letter[:1].lower() # Add that letter to the current string.


                # Switches the players
                if curr_player == 1:
                    curr_player = 2
                else:
                    curr_player = 1




                for key, value in get_words.items(): # Iterates through every key and value ina dictionary
                    if curr_str == key: # If the current string equalsa word aka Key
                        if curr_player == 1: # And if the palyer is player 1 
                            points[0] += value #Give player one the value of the key
                            del get_words[key] # delete that key from the dictionary
                            round_over = True #Set round over equal back to true


                            print '=' * 50
                            print 'Round %s over' % curr_round                                                                  # } 
                            print ''
                            print 'Player %s won with %s points, \n \nwinning word was %s' % (curr_player, points[0], curr_str) # } Declare the resuults
                            print '=' * 50
                            curr_str = ''
                            break

                        else:
                            points[1] += value
                            del get_words[key]
                            round_over = True


                            print '=' * 50
                            print 'Round %s over' % curr_round
                            print ''
                            print 'Player %s won with %s points, \n \nwinning word was: >> %s' % (curr_player, points[1], curr_str)
                            print '=' * 50
                            curr_str = ''
                            break

有谁能告诉我为什么我的代码会循环回L93而不是L82?欢迎所有答案。非常感谢你。

0 个答案:

没有答案
相关问题