Guess the number game python

game introduction

First of all, let the user input freely, but make a judgment on the input value. Only when the user enters a value, the program will be executed. If the input is not a value, the corresponding error message will be given and re-input

Start the comparison when it is determined that the user input is a number

(1): If the input number is greater than the number to be guessed, a corresponding prompt message should be given to remind the user

(2): Similarly, when the input number is smaller than the number to be guessed, the corresponding information should be given to the user

(3): After the user guesses the number, it will give "Congratulations, you have guessed the words correctly, and start to execute the drawing operation"
 

Above code:

import random

randomnumber = random.randint(1, 10000)//取值范围可以自己改
flag=False
a=int(input("猜一猜,请输入一个整数:"))
while flag==False:
    if a>randomnumber:
         print("哈哈,你猜的数太大了!")
         a=int(input())
    elif a<randomnumber:
         print("哈哈,你猜的数太小了!")
         a = int(input())
    else:
         print("恭喜你,猜对了!")
         flag=True

Guess you like

Origin blog.csdn.net/qq_57435798/article/details/123418945