This article introduces how to use Python to implement a simple guess digital game example code Python to implement a simple guess digital game, as shown below:
Generate a random number between 1 and 10 for the user to guess. when the guess is incorrect, the system will prompt whether the number is large or small until the user guesses right.
Import randomsecret = random. randint () # print (secret) print ('------ guess digital game! ----- ') Guess = 0 while guess! = Secret: temp = input ('Start with a number game. enter the number: ') guess = int (temp) if guess> secret: print (' The number you entered is too large! ') Else: print (' The number you entered is small! ') If guess = secret: print ('Congratulations, you guessed it! ') Print ('The game is over. goodbye! ^_^ ')
The above is the details of the sample code for a simple guess digital game using Python. For more information, see other related articles in the first PHP community!