Dry Goods Collection | Python Realizes Number Guessing Game

Insert picture description here
Today, we use Python to implement a simple number guessing game. The specifics are as follows: randomly generate a number between 1-100 and let the user guess. When the guess is wrong, it will prompt whether the guessed number is big or small until the user guesses it right.
Overall code:
#This is a guessing number game. Guess numbers between 1-100
import random
num=random.randint(1,100)
print('This is a number guessing game, you can enter numbers between 1 and 100, but there are only 5 chances')

for guesstake in range(1,6):
	print('请输入一个数字')
	guess=int(input())

	if guess < num:
		print('你输入的数字太小了')
	elif guess > num:
		print('你输入的数字太大了')
	else:
		break

if guess == num:
	print('恭喜!你猜对了!你用了'+ str(guesstake) +'次')
else:
	print('数字是'+ str(num) +' 继续努力!')
input()

The above is the specific implementation steps, welcome to refer to.
Part of the content of the article comes from the Internet, contact intrusion and deletion* The
article reference comes from http://http.taiyangruanjian.com/news/54872.html

Guess you like

Origin blog.csdn.net/zhimaHTTP/article/details/111931950