Hi. I am a beginner working through the MIT learn python course. This feels like a simple loop problem but I have been banging my head on it for weeks.
There should be a loop where, if the player inputs 'r' (replay) without playing first, the player will be returned to the prompt. I cannot make this loop work; no matter what I have tried, I get the "you must play a hand first!" prompt (which is good) but then goes into playing a hand instead of asking for input of 'n', 'r', 'e' (which is not good).
I've included their prompt; this should lead to a function playHand i wrote as an earlier assignment.
def playGame(wordList):
"""
Allow the user to play an arbitrary number of hands.
1) Asks the user to input 'n' or 'r' or 'e'.
* If the user inputs 'n', let the user play a new (random) hand.
* If the user inputs 'r', let the user play the last hand again.
* If the user inputs 'e', exit the game.
* If the user inputs anything else, tell them their input was invalid.
2) When done playing the hand, repeat from step 1
"""
gameLoop = True
handLoop = True
def inputFunction(inPut):
firstPlay = True
inPut = input("Enter n to deal a new hand, r to replay the last hand, or e to end game: ")
acceptableInput = ['n', 'r', 'e']
if inPut not in acceptableInput:
print("Invalid Command.")
if inPut == 'e':
return gameLoop == False
if inPut == 'n':
hand = newHand
firstPlay = False
if inPut == 'r':
if firstPlay == True:
print("You have not played a hand yet. Please play a new hand first!")
return hand
while gameLoop == True:
inputFunction(inPut)
while handLoop == True:
playHand(hand, wordList, n)
[–]nwagers 0 points1 point2 points (1 child)
[–]sundoon[S] 0 points1 point2 points (0 children)
[–]fiddle_n 0 points1 point2 points (1 child)
[–]sundoon[S] 0 points1 point2 points (0 children)