Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def playGame(wordList):
- hand = {}
- user_input = ""
- n = HAND_SIZE
- while user_input != "e":
- while True: # checking and reacting on first input
- user_input = input("Enter n to deal a new hand, r to replay the last hand, or e to end game: ")
- try:
- if user_input not in ('n', 'r', 'e'):
- raise Exception
- except Exception:
- print("Invalid command.")
- print("")
- else:
- try: # What if HAND is empty and it can not REPLAY
- if user_input == "r":
- if sum(hand.values()) == 0:
- raise Exception
- except Exception:
- print("You have not played a hand yet. Please play a new hand first!")
- else:
- print("")
- break
- # Handle exception
- if user_input == "e":
- break
- while True: # checking and reacting on second input
- user_input2 = input("Enter u to have yourself play, c to have the computer play:")
- try:
- if user_input2 not in ('c', 'u'):
- raise Exception
- except Exception:
- print("Invalid command.")
- print("")
- else:
- print("")
- break
- # if inputs are correct continue below
- if user_input == "r":
- if user_input2 == 'c':
- compPlayHand(hand, wordList, n)
- else:
- playHand(hand, wordList, n)
- if user_input == "n":
- hand = dealHand(n)
- if user_input2 == 'c':
- compPlayHand(hand, wordList, n)
- else:
- playHand(hand, wordList, n)
- print("")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement