python games practicing hand - Guess

#! / usr / bin / env Python 
# Coding = UTF-8

Import Random

# guessed the player's digital preservation to this variable, because the players have not done any speculation, so preservation is an integer 0
guessesTaken = 0

Print ( 'the Hello! the What iS your name?')
MyName = the iNPUT ()

# input to determine whether there is value in the MyName
# does not exist, you need to tell the user input string, you can not directly enter or spaces instead
if MyName == " ":
Print ( '!? Please name the Hello the What iS your the iNPUT String')
MyName = the iNPUT ()
the else:
# If not, direct customer input output to the console, allowing customers to confirm
print ( 'your name is' + MyName )

# generates a random number and a number stored in a variable
number the random.randint = (. 1, 20 is)

Print ( 'Well,' MyName + + ', of the I AM a numbert betwen the Thinking. 1 and 20. a')
for I in Range (l, 7):
Print ( 'the Take A GUESS.')
# = GUESS INPUT () a user input string #
# Guess = int (guess) # The user input string into an integer format
# to be used flexibly int (), float (), str () and BOOL () function
# 2 above, the combined command is used together, as follows guess int = (iNPUT ())
# catch exceptions guessing when the number is not received, to re-enter
the try:
GUESS = int (iNPUT ())
IF GUESS <number:
Print ( 'Your GUESS iS TOO Low.')
gUESS IF> number:
Print ( 'Your gUESS iS TOO High.')
IF gUESS == number:
BREAK
the except a ValueError:
Print ( 'INPUT number Please use int')
gUESS = int (INPUT ())


the number of records guess #, with the following guessesTaken output
guessesTaken + =. 1

IF GUESS == Number:
guessesTaken = STR (+ guessesTaken. 1)
print('Good Job, ' + MyName + '! You guessed my number in ' + guessesTaken + ' guesses!')


if guess != number:
number = str(number)
print('Nope. The number I was thinking of was ' + number + '.')

 

Guess you like

Origin www.cnblogs.com/fatyao/p/11223667.html