python写个猜数字游戏,判断反应能力

今天简单学习了下python中time函数,写了一个我们平常经常玩的猜数字小游戏

直接上代码如下:

# <-*- coding:UTF-8 -*->
import random
import time
if __name__=='__main__':
    play=input("Are you ready:(\'yes\' or \'no\')\n")
    while play == "yes":
        rn=random.randint(0,101)
        start=time.perf_counter()
        guess=int(input("please input a 0-100 integer\n"))
        while guess!=rn:
            if guess>rn:
                guess = int(input("please input smaller number\n"))
            else:
                guess = int(input("please input bigger number\n"))
        end=time.perf_counter()
        c=end-start
        print("you cost time is:%ss"%c)
        if c<=10:
            print("you are so smart")
        elif c<=15:
            print("you are clever")
        elif c<=20:
            print("you are normal")
        else:
            print("come on")
        print("you guess number is %d"%guess)
        print("Congratulation,you are right")
        play = input("do you want to play it:(\'yes\' or \'no\')\n")

运行结果如下:

D:\MyPro\venv\Scripts\python.exe D:/MyPro/Python_Work/12.py
Are you ready:('yes' or 'no')
yes
please input a 0-100 integer
23
please input smaller number
10
please input bigger number
16
please input smaller number
14
please input smaller number
13
please input smaller number
15
please input smaller number
14
please input smaller number
11
you cost time is: 30.5828832
come on
you guess number is 11
do you want to play it:('yes' or 'no')
yes
please input a 0-100 integer
56
please input smaller number
30
please input smaller number
20
please input bigger number
26
please input bigger number
28
you cost time is: 16.117239200000007
you are normal
you guess number is 28
do you want to play it:('yes' or 'no')
no

Process finished with exit code 0

反应不行啊!但是每天多学习,肯定可以提高的
路过的也可以试下自己的反应能力哦,哈哈哈!!!

你可能感兴趣的:(每天学习点python,python)