|
|
马上注册,结交更多好友,享用更多功能,让你轻松玩转新大榭论坛!
您需要 登录 才可以下载或查看,没有账号?注册
x
题目:时间函数举例4。% ~$ |# ]5 D# y. D1 j$ T$ y% ^
程序分析:如何浪费时间% E, E/ {+ S$ a( ~" _
- if __name__ == '__main__':
9 `0 u+ m' A( ` - import time' }! ?& c$ X1 D$ e i
- import random" Z) l! n: t6 }
-
R# h+ G& U ]& `- T( a - play_it = input('do you want to play it.(\'y\' or \'n\')')
+ x1 s2 ~4 b! @; ~/ F - while play_it == 'y':
& d( C; h) ]2 [8 H$ } k - c = input('input a character:\n')
4 D1 s. \: U+ m6 L; f - i = random.randint(0,2**32) % 100
! Y- ` n' v. n3 B% e7 p - print ('please input number you guess:\n')
( h: V# Q% f6 O, ?5 D3 h - start = time.clock()" I8 o( w$ U9 ?
- a = time.time()1 Y$ Z4 m& }/ Z$ `0 |2 u
- guess = int(input('input your guess:\n'))4 ]2 U6 x: e( @; O, F8 S2 g
- while guess != i:
$ L& |) W G/ L& R6 D) _3 V - if guess > i:
5 G- i" t0 |& g" s g - print('please input a little smaller')$ V K, E$ L) L6 _: \* m( ^8 n7 c
- guess = int(input('input your guess:\n'))' K8 k ]# S# k/ l7 |) C: c/ e
- else:7 O7 ~1 T. L3 v( l# O- |7 t7 `
- print('please input a little bigger')
& t u) z' Y7 K - guess = int(input('input your guess:\n'))
1 p* J5 G8 D: h8 { - end = time.clock()
3 t7 a! e1 ? r6 R. `/ n5 c - b = time.time()6 H% A. W1 n# B4 o; ?+ M$ x# p$ H
- var = (end - start) / 18.2
. ]) k1 z' Q1 O; C5 T4 g - print (var)% W A1 n( q+ a
- # print 'It took you %6.3 seconds' % time.difftime(b,a))
$ z: Z* l- l. {: e1 ^3 w - if var < 15:# M& M* }, C# X5 G
- print ('you are very clever!')( c; n6 s$ o! f: x* s; H% e F3 Z
- elif var < 25:
3 {) E0 w. O0 I& I- Q - print ('you are normal!')6 J8 P( X7 @) ~* {9 Z/ z
- else:
% S0 [+ _, ^0 g- M- J/ B& ` - print ('you are stupid!')/ H+ Z; c# h0 H" i* K" h
- print ('Congradulations')! [1 x) o: F9 c ?/ d
- print ('The number you guess is %d' % i)
. Y. z& o9 C2 X2 Y! z7 c - play_it = input('do you want to play it.')
复制代码 |
|