欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

python练习题(五十):一个猜数游戏,判断一个人反应快慢

程序员文章站 2024-03-11 20:00:13
...
# 题目:
# 时间函数举例4,
# 一个猜数游戏,判断一个人反应快慢。

import random
import time

flag = True
up = 100

while flag:
    play = input("Do you want to play?(y or n):")
    if play == 'y':
        print("Start the game!")
        a = random.randint(0, up)
        start_time = time.clock()
        while True:
            guess = int(input("input your guess(between 0 and %d):" % up))
            if guess == a:
                end_time = time.clock()
                total_time = end_time - start_time
                print("Successful!\nYour total time = %f s" % total_time)
                if total_time <= 15:
                    print("You are very clever!")
                elif total_time <= 25:
                    print("You are normal.")
                else:
                    print("You are stupid...")
                print("*" * 50)
                break
            elif guess < a:
                print("your guess is too smaller!")
            else:
                print("your guess is too bigger!")
    else:
        flag = False
        print("Quit the game!")
        break

运行结果:
python练习题(五十):一个猜数游戏,判断一个人反应快慢

相关标签: python练习题