Advertisement
Guest User

Untitled

a guest
Jul 15th, 2018
65
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.83 KB | None | 0 0
  1. import random
  2. import math
  3. import time
  4.  
  5. def askIfPlay():
  6. wantPlay = False
  7. askPlay = str(input("Do you want to play MASTERMIND?: "))
  8. askPlay = askPlay.lower()
  9.  
  10. if(askPlay.startswith("y")):
  11. wantPlay = True
  12. difficultyAndNumbers([])
  13. else:
  14. quit()
  15.  
  16. def difficultyAndNumbers(difficultyRating):
  17. rulesPrint = print("Make sure to seperate the numbers with a comma!")
  18.  
  19. uDiff = int(input("Choose difficulty 1-3: "))
  20. orderCorrect = False
  21. if(uDiff == 3):
  22. orderCorrect = True
  23. else:
  24. orderCorrect = False
  25.  
  26. Attempts = 10
  27. numbersGuess = 4
  28. Attempts -= int(uDiff*2)
  29. numbersGuess += uDiff
  30.  
  31. numberStore = []
  32. numbersGenerated = 0
  33. while(numbersGenerated <= numbersGuess):
  34. numGen = random.randint(0,9)
  35. numbersGenerated += 1
  36. numberStore.append(numGen)
  37. if(len(numberStore) == numbersGuess):
  38. print(numberStore)
  39.  
  40. if(orderCorrect == True and Attempts != 0):
  41. print("This is going to be almost impossible! You have to"
  42. "guess the numbers in the right order!")
  43. print(rulesPrint)
  44. print("You have", Attempts, "tries to get this right!")
  45.  
  46. while(Attempts >= 0):
  47. playerGuess = str(input("Guess: "))
  48. playerGuess = [int(playerGuess) for playerGuess in playerGuess.split(',')]
  49. if (playerGuess != numberStore):
  50. print("You guessed wrong!")
  51. print("You have", Attempts, "tries left.")
  52. Attemtpts -= 1
  53. elif(any(playerGuess == numberStore)):
  54. print("You have the right numbers, now you have to guess the order")
  55. print("You have", Attempts, "tries left.")
  56.  
  57. elif(playerGuess == numberStore):
  58. print("You win! You guessed it right!")
  59. print("Might I add, you're a god.")
  60.  
  61. elif(orderCorrect == False and Attempts != 0):
  62. while(Attempts >= 0):
  63. playerGuess = str(input("Guess: "))
  64.  
  65. playerGuess = [int(playerGuess) for playerGuess in playerGuess.split(',')]
  66. if any(playerGuess != numberStore):
  67. print("You guessed wrong!")
  68. print("You have", Attempts, "tries left.")
  69. Attempts -= 1
  70. elif any(playerGuess == numberStore):
  71. print("You win! You guessed it right!")
  72.  
  73. if(Attempts <= 0):
  74. tryAgain = str(input("Sorry, you've ran out of tries! Do you want to play again?"))
  75. tryAgain = tryAgain.lower()
  76. if(tryAgain.startswith("y")):
  77. askIfPlay()
  78. else:
  79. print("Thanks for playing")
  80. time.sleep(2)
  81. quit()
  82.  
  83. askIfPlay()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement