A Short Program: Guess The Number:: "I Am Thinking of A Number Between 1 and 20."
A Short Program: Guess The Number:: "I Am Thinking of A Number Between 1 and 20."
print("Take a guess.")
guess = int(input())
else:
if guess == secretNumber:
else:
import random
The program imports the random module...
######################################################
The program tells the player that it has come up with a secret number and will give
the player six chances to guess it.
This gets stored in a variable named Its return value passed a straight into int(), which translate the string
guess. into an integer value.
######################################################
if guess < secretNumber: These few lines of code check to see whether the guess is
less than or greater than the secret number
print("Your guess is too low.") (secretNumber). In the either case, a hint is printed to the
scree.
elif guess > secretNumber:
######################################################
else:
If the guess is neither higher or lower than the secret number, then it must be equal to the
secret number – in which case, you want the program execution to break out of the for loop.
######################################################
if guess == secretNumber:
print("Good Job!, You guessed my number in: " + str( guessesTaken )+ "guesses!")
else: