2020.10.28 training exercise one

``Although the training activities on this day are not long, I still learned something from it. When I taught myself before, I didn't memorize some data typologies carefully, which is not deeply ingrained in my mind. Numerical operators are nothing more than addition, subtraction, multiplication and division in mathematics, power, rounding, remainder, and exponentiation. This is a small problem in daily life, but if you want to make the machine too, you have to do a little work, first of all To make it understand, the communication between people still needs to organize language, and computers that don’t understand human relationships and sophistication require us to be patient. If you don’t talk to it properly, it will report a lot of errors to you, although it is difficult to talk. , But it is still very obedient. It is absolutely due diligence to let it run the program. After the first step, it will be driven by you. As long as it does not terminate, it will continue to work. The machine is working, ah, what am I doing, hurry up and learn mathematics Go, have you done a few points, have the high generation done it, how many solutions, don’t hurry up after typing; cough, digress, Boolean value, true value and false value, 0 false 1 true, True and False; l list, Dictionary, Yuan Dian, collection, the difference between the four, additions, deletions, revisions, etc.... There are many people, if you have time, you can read it again. No matter how bad, it will not take much time to copy it a few times.
The above is all nonsense, the following is.

The big bang of numbers
first understand the rules of the game. The system randomly selects a random number within a given range. Within the range, humans and machines take turns to guess. Each time it is guessed, it is judged whether it is a random number. If it is not, it will prompt whether it is too large or too small. Guess again, until you guessed it, if it's a random number, it's OK, and there's no work to do.
Look at the knowledge points, character input and output, logic design (if, while, for, etc.), the call of the function package, and the others don’t know what else to understand, hahaha.
Finally, let’s take a look at how to design this game.
1. Briefly describe the rules of the game.
2. Choose random numbers, and please prepare for humans and machines.
3. People guess first. After guessing, the system will judge, =,>,<three types of discussion , the machine according to the new guess complete range guess, who should guess who won, win guessing game has ended, too monotonous, not give the whole point of unitary moths
4, the beginning of the countdown
5, the number of computations guess
6, defined guess The number of times, guessing too much will explode, please cherish the last number of times
7.over The
following is the code, the code word is not easy, there is something wrong, please correct me

import random#导入随机模块
import time#导入时间模块
print("游戏为猜数游戏,双方对弈,在有限次数内猜数,谁先猜中就炸") #介绍游戏规则    
print("随机数已生成,做好准备,游戏将在三秒倒数后开始")#游戏提醒
dic={
    
    'min':1,'max':1000} #用字典接收min与max的变化
j = 3    #开始计数
while 0 < j:
    print(j,end='\t')
    time.sleep(1)#时间间隔
    j -= 1
print("\n游戏开始")#游戏开始
print("随机数开始范围是[1,1000]")#告知范围
guess_time = 0#记录次数
rd=random.randint(dic['min'],dic['max'])#生成随机数
while True:#开始循环
    your_num = int(input("请你猜一个在该范围中的数:"))#提醒用户输入
    while your_num<dic['min'] or your_num>dic['max']:#判断用户输入是否有误
        your_num = int(input("你输入数字超出范围,请重新输入:"))#提醒重新输入
    guess_time += 1#次数变化
    if your_num < rd:#一情况
        print(f"你的数字比答案小,数字范围将改为[{your_num+1},{dic['max']}]")#提醒用户与答案的差距,范围将发生改变
        dic['min']=your_num+1#范围变化
        # rd = random.randint(dic['min'], dic['max'])
        machine_num=random.randint(dic['min'],dic['max'])#机器选数
        print(f'机器猜测的数字是{machine_num}')#通报
        if machine_num<rd:#一情况,以下参上,不再赘述
            print(f"机器的数字比答案小,数字范围将改为[{machine_num + 1},{dic['max']}]")
            dic['min'] = machine_num + 1
        elif machine_num>rd:
            print(f"机器的数字比答案大,数字范围将改为[{dic['min']},{machine_num-1}]")
            dic['max'] = machine_num -1
        else:
            print('机器猜中了,机器要炸了')
    elif your_num > rd:
        print(f"你的数字比答案大,数字范围将改为[{dic['min']},{your_num-1}]")
        dic['max'] = your_num - 1
        # rd = random.randint(dic['min'], dic['max'])
        machine_num = random.randint(dic['min'], dic['max'])
        print(f'机器猜测的数字是{machine_num}')
        if machine_num<rd:
            print(f"机器的数字比答案小,数字范围将改为[{machine_num + 1},{dic['max']}]")
            dic['min'] = machine_num + 1
        elif machine_num>rd:
            print(f"机器的数字比答案大,数字范围将改为[{dic['min']},{machine_num-1}]")
            dic['max'] = machine_num -1
        else:
            print('机器猜中了,机器炸了')
            break
    else:
        print('妙啊,你炸了!')
        break
    if guess_time == 9:
        print("猜测次数过多,游戏结束")
        break
print("欢迎下次再来")
print(f"你一共猜了{ guess_time}次" )

Here is one of my own
Insert picture description here

This homework is coming to an end. At the end, I would like to say a few more words. Thank you very much for the training of the brothers and sisters. I can say that I am a novice in this field. I am not familiar with many aspects, or even don’t know. , But seeing that my friends in the department are so good, I have to force myself to learn, and I am also willing to make progress. I don’t want to talk about it anymore. I still have to write mathematics and slip away.

Guess you like

Origin blog.csdn.net/weixin_50335890/article/details/109357810