Number Guess is a simple and fun game that allows players to guess a randomly generated number. In this article, we will use Python to write a guessing game program to let you experience this interesting game.
First, let's look at the basic idea of the program. We will generate a random integer as the answer, and then the player can guess the answer by entering the guessed number. The program will provide corresponding hints based on the player's guess until the player guesses the correct answer.
Let’s start coding!
import random
def guess_number():
answer = random.randint(1, 100) # 生成1到100之间的随机整数
attempts = 0