The student will learn the following new concepts:
The student will practice the following programming concepts:
Program Stub
import random def nextSceretNumber(): """ Sets a random secret number pre-condition: None post condition: a random number from 1 to 10 is returned """ return random.randint(1,10) def nextGuess(): """ prompts the user for a guess this method assumes a valid integer will be entered by the user pre-condition: none post condition: returns the users guess """ usersGuess = int(input("Enter Your Guess: ")) return usersGuess def isCorrect(guess, secret): """ :param guess :param secret :return True if the the guess and the secret numbers are the same pre-condition: the guess and secret number are available post condition: returns True if the the guess and the secret numbers are the same """ return (guess == secret) def isNotCorrect(guess, secret): """ :param guess :param secret :returns True if the the guess and the secret numbers are NOT the same pre-condition: the guess and secret number are available post condition: returns True if the the guess and the secret numbers are NOT the same """ return not isCorrect(guess,secret) def printHint(guess, secret): """ :param guess :param secret pre-condition: the guess in not correct post condition: prints a hint to the user to guess higher or lower """ print ("You are NOT correct") def printAWinner(guess): """ pre-condition: The user has guessed the correct number post condition: The winning message is displayed """ print ("You are correct") def playGuessIt(): """ pre-condition: None post condition: one game of Guess has been played """ secret=nextSceretNumber() guess=nextGuess() if isNotCorrect(guess, secret): printHint(guess,secret) else: printAWinner(guess) def main(): playGuessIt() if __name__ == '__main__': main()
PART 3
Count the number of guesses it take the user find the secret number