|
|
马上注册,结交更多好友,享用更多功能,让你轻松玩转新大榭论坛!
您需要 登录 才可以下载或查看,没有账号?注册
x
题目:时间函数举例4。
" M( m& k# H3 _/ A程序分析:如何浪费时间' G. S& s" s: e% c0 D: i' z7 W( r
- if __name__ == '__main__':
) m8 I/ t6 ?1 q. i7 C$ c. o8 R - import time
' |- ?4 f4 Y K - import random8 d" h3 n6 i: q! }1 H
- 8 u/ I$ p, R9 C, I
- play_it = input('do you want to play it.(\'y\' or \'n\')')
! [2 m2 B& t/ ~. T% u4 O - while play_it == 'y':5 D9 U9 G. s+ p4 F3 c0 o" E
- c = input('input a character:\n')% b! }! j, k, r* M0 k2 S" O3 g' W5 v
- i = random.randint(0,2**32) % 100/ z3 C: g3 }. k1 ~
- print ('please input number you guess:\n')1 {+ H/ ]4 c' F+ U. s8 j& W' G9 Z
- start = time.clock()
7 F" ]5 E" W* `0 c! S/ f - a = time.time()
( h, v5 A* \; A3 ` - guess = int(input('input your guess:\n'))
3 X r1 a6 I/ V+ G. N - while guess != i:' a2 p9 c- e! Y2 G0 w# `- [
- if guess > i:
5 \& f( w1 U3 w" Q+ f( B# @ - print('please input a little smaller')3 x% W3 ?6 [8 ~+ y* v. S
- guess = int(input('input your guess:\n'))
3 D% P8 n# p6 j; M$ F& v$ P: M( w - else:
* B4 l5 j0 W+ V6 ? - print('please input a little bigger')! Z) m9 X& n% J! C
- guess = int(input('input your guess:\n'))
: ?5 ^/ ]: ]' h- V - end = time.clock()
2 i* d; j) d% _ - b = time.time()
. ~( @: G& e$ @2 { - var = (end - start) / 18.22 a( h8 E6 i0 z- O5 d* x$ z5 L
- print (var)
2 h! p: X& m" C/ i3 O8 d p% f - # print 'It took you %6.3 seconds' % time.difftime(b,a))
$ J q( ?8 i6 ]; a% i0 I e - if var < 15:- ^2 E8 b( A. k; ~# a
- print ('you are very clever!')
$ P. `; g, {0 P6 P% R4 n; Y7 H - elif var < 25:
% M& }5 p& n% l4 P - print ('you are normal!')
! f0 @/ `& J9 i - else:
6 S& Y' [: o& q2 x* x( i3 n - print ('you are stupid!')2 G5 x$ ]2 M) B- |' w% S
- print ('Congradulations')$ a3 Q: @( H6 v2 w% Y# b/ Z- j
- print ('The number you guess is %d' % i)4 {) `. V5 @( B- S. n4 Y7 @
- play_it = input('do you want to play it.')
复制代码 |
|