vendredi 17 juin 2016

Code won't loop through the correct while loop. Python

I am trying to make my code loop through a while loop for a certain period of time, however it keeps looping through the wrong while loop. Here is the code.

    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

Can anyone tell me why my code keeps looping back to L93 instead of L82? Every and all answers are welcome. Thank you very much.

Aucun commentaire:

Enregistrer un commentaire