Advertisement
superpawko

Untitled

Oct 8th, 2016
44
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.31 KB | None | 0 0
  1. while user_input != "e":
  2. while True: # checking and reacting on first input
  3. user_input = input("Enter n to deal a new hand, r to replay the last hand, or e to end game: ")
  4. try:
  5. if user_input not in ('n', 'r', 'e'):
  6. raise Exception
  7.  
  8. except Exception:
  9. print("Invalid command.")
  10. print("")
  11. else:
  12.  
  13. try: # What if HAND is empty and it can not REPLAY
  14. if user_input == "r":
  15. if sum(hand.values()) == 0:
  16. raise Exception
  17. except Exception:
  18. print("You have not played a hand yet. Please play a new hand first!")
  19. else:
  20. print("")
  21. break
  22. # Handle exception
  23. if user_input == "e":
  24. break
  25.  
  26. while True: # checking and reacting on second input
  27. user_input2 = input("Enter u to have yourself play, c to have the computer play:")
  28. try:
  29. if user_input2 not in ('c', 'u'):
  30. raise Exception
  31. except Exception:
  32. print("Invalid command.")
  33. print("")
  34. else:
  35. print("")
  36. break
  37.  
  38. # if inputs are correct continue below
  39.  
  40. if user_input == "r":
  41. if user_input2 == 'c':
  42. compPlayHand(hand, wordList, n)
  43. else:
  44. playHand(hand, wordList, n)
  45. if user_input == "n":
  46. hand = dealHand(n)
  47. if user_input2 == 'c':
  48. compPlayHand(hand, wordList, n)
  49. else:
  50. playHand(hand, wordList, n)
  51. print("")
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement