PYTHON   52
playgame wordList
Guest on 26th August 2023 12:38:36 AM


  1.  
  2. def playGame(wordList):
  3.     """
  4.    Allow the user to play an arbitrary number of hands.
  5.  
  6.    1) Asks the user to input 'n' or 'r' or 'e'.
  7.      * If the user inputs 'n', let the user play a new (random) hand.
  8.      * If the user inputs 'r', let the user play the last hand again.
  9.      * If the user inputs 'e', exit the game.
  10.      * If the user inputs anything else, tell them their input was invalid.
  11.  
  12.    2) When done playing the hand, repeat from step 1
  13.    """
  14.     # TO DO ... <-- Remove this comment when you code this function
  15.     hand = False
  16.     while True:
  17.         user = raw_input("Enter n to deal a new hand, r to replay the last hand, or e to end game: ").lower()
  18.         if user not in 'nre':
  19.             print("Invalid command.")
  20.         else:
  21.             if user == 'r' and not hand:
  22.                 print("You have not played a hand yet. Please play a new hand first!")
  23.             elif user == 'n':
  24.                 hand = dealHand(HAND_SIZE)
  25.                 playHand(hand.copy(), wordList, HAND_SIZE)
  26.             elif user == 'r' and hand:
  27.                 playHand(hand.copy(), wordList, HAND_SIZE)
  28.             else:
  29.                 break
  30.             print("")
  31.  
  32. playGame([a, s, r, e, t, t, t]):

Raw Paste

Login or Register to edit or fork this paste. It's free.