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
运行结果:
上一篇: 2010西安电子科技大学计算机机试题目
下一篇: 07- 变量的高级主题(下)