100-094

时间函数举例4,一个猜数游戏,判断一个人反应快慢。
 1 #! /usr/bin/env python
 2 # -*- coding:utf-8 -*-
 3 '''
 4 时间函数举例4,一个猜数游戏,判断一个人反应快慢。
 5 '''
 6 import time
 7 import random
 8 start = time.time()
 9 while True:
10     play=input('play the game(y/n)?')
11     if play == 'y':
12         number = int(random.randint(0,1000))
13         guess = int(input('guess a number: '))
14         while True:
15             if number > guess:
16                 guess = int(input("guess a bigger number: "))
17             elif number < guess:
18                 guess = int(input("guess a smaller number: "))
19             else:
20                 end = time.time()
21                 print ("bingo! ")
22                 print (u"%0.2fs猜中"%(end-start))
23                 break
24     else:
25         break

 

posted @ 2018-06-27 20:47  睡到自然醒的猪  阅读(161)  评论(0)    收藏  举报

iaoexl at outlook dot com, 返回顶部 →友情链接: 信息港 同城信息