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

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

  • 1
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值