In this example, we'll set PH[0] to 'Ten of Hearts', and guess to 'Ten'
The list 'PH' represents a Player's Hand in a card game of Go Fish. When the user guesses a card, they have to guess a card that corresponds with a card in their hand. I wrote this block of code so that if the user inputs an invalid guess (if the guess is not in PH, they will be prompted again to enter a new guess)
I feel like I am having problems with the variables in the array [guess1, guess2, guess3, guess4], but I am not too sure.
When the code is executed, the loop goes on forever. I need to be able to get out of the loop in order to return the guess so it can be entered into the next function.
If someone could please help me solve the problem I'm having.
guess = str(raw_input("Make a guess : "))
guess11 = guess, 'of Hearts'
guess1 = " ".join(guess11)
guess22 = guess, 'of Diamonds'
guess2 = " ".join(guess22)
guess33 = guess, 'of Clubs'
guess3 = " ".join(guess33)
guess44 = guess, 'of Spades'
guess4 = " ".join(guess44)
while PH[0] not in [guess1, guess2, guess3, guess4] :
print "You do not have a card like that in your hand."
guess = str(raw_input("Make another guess : "))
guess11 = guess, 'of Hearts'
guess1 = " ".join(guess11)
guess22 = guess, 'of Diamonds'
guess2 = " ".join(guess22)
guess33 = guess, 'of Clubs'
guess3 = " ".join(guess33)
guess44 = guess, 'of Spades'
guess4 = " ".join(guess44)
return guess
PH[0]to'Ten of Hearts'andguessto'Ten'. The loop exits correctly.raw_inputis already a string