新大榭论坛

 找回密码
 注册

QQ登录

只需一步,快速开始

《新大榭》- 创大榭地方网络社区先锋品牌 新大榭始终专注于地方网络社区平台的建设 关于我们- [大记事]- 留言建议- [新手报道]

发布 .新大榭软件管家(Excel版) V6.0版 财务/仓库/生产/销售/采购/行政/人事/校园 .公告 - 客户 - 打赏 - 职场 - Excel - Python.

新大榭镜像-音乐-法律-图书-高中课堂-实验 广告是为了能更好的发展 [欢迎商家支持本站互利共赢] 广告位招租.首页黄金广告位等您来!联系 13566035181

查看: 1256|回复: 0

[题库] 7954 - [D]实例094:time模块IV

[复制链接]
发表于 2021-10-23 07:44:25 | 显示全部楼层 |阅读模式

马上注册,结交更多好友,享用更多功能,让你轻松玩转新大榭论坛!

您需要 登录 才可以下载或查看,没有账号?注册

x
题目:时间函数举例4。
1 Z  e0 r2 \( W7 z( _+ p' I6 R% j程序分析:如何浪费时间# U' w# W3 T) |
  1. if __name__ == '__main__':
    5 N. V; j2 \1 {( H  R
  2.     import time5 B6 P  F2 g$ C5 j8 g, z/ z
  3.     import random# v2 N8 {  w5 q, ~3 A9 C
  4.    
    ; q, h% O* F. y0 u& i  T
  5.     play_it = input('do you want to play it.(\'y\' or \'n\')')
    8 p/ P3 z& E5 M& @) P
  6.     while play_it == 'y':/ F3 M+ s( B4 i
  7.         c = input('input a character:\n')
    8 `* _0 c) g4 b  R) B
  8.         i = random.randint(0,2**32) % 100' w9 Y+ Z+ |7 G  I! J
  9.         print ('please input number you guess:\n'). U) r/ n/ D% b7 |
  10.         start = time.clock()7 k# n/ q. ?+ `% m! v: N5 w- v
  11.         a = time.time()
    . E9 u6 ?+ E- v4 `7 P' f
  12.         guess = int(input('input your guess:\n'))
      p: L* M8 u( n( M* Q0 M% X
  13.         while guess != i:) A- I6 V2 f$ I! }! P/ Q1 @( Z
  14.             if guess > i:, }4 N6 T0 k3 Z
  15.                 print('please input a little smaller')( V$ t: {5 A! _: e& ]# d, z
  16.                 guess = int(input('input your guess:\n'))
    0 X" k% ~2 L: i4 h* s1 e- T
  17.             else:
    3 P, f; [1 j3 _# h3 X+ m
  18.                 print('please input a little bigger')
    4 X7 S0 C0 i7 d) h
  19.                 guess = int(input('input your guess:\n'))
    , G9 |# h; M3 x4 j4 T; Z
  20.         end = time.clock()
    9 r4 s" F9 D2 q- G& l
  21.         b = time.time()- i' ]" K! D0 k  k
  22.         var = (end - start) / 18.2; c* ~6 \5 u& _+ o, l; _; y
  23.         print (var)
    ; Z( q5 U; d# u, z' E3 L
  24.         # print 'It took you %6.3 seconds' % time.difftime(b,a))4 D9 t0 M8 e) i* M' L
  25.         if var < 15:
    8 L: f7 K# K* A, l4 |$ X
  26.             print ('you are very clever!')# X0 _3 [, G( o4 k) I
  27.         elif var < 25:. u" X+ F; R6 R( l9 P' F3 |
  28.             print ('you are normal!')
    " W" x- T) W. ~9 }8 B
  29.         else:
    : ?+ s& f; a4 o7 {
  30.             print ('you are stupid!')( j+ a5 {/ y/ _7 r8 e  Y! M# b& `
  31.         print ('Congradulations')1 ]6 x3 S- _- l5 {: f  |
  32.         print ('The number you guess is %d' % i)
    ) l7 w7 G5 ]8 e' R! V
  33.         play_it = input('do you want to play it.')
复制代码
新大榭Python学习社区培训、Excel业务指导、办公软件定制、网站建设;新大榭探索实验室欢迎您!http://lab.daxie.net.cn/
Q群推荐 大榭本地求职招聘QQ群,欢迎转发分享本地招聘信息资讯! 官方招聘1群(已满);官方招聘2群:315816937 *
您需要登录后才可以回帖 登录 | 注册

本版积分规则

文字版|小黑屋|新大榭 ( 浙ICP备16018253号-1 )|点击这里给站长发消息|

GMT+8, 2026-5-15 11:07 , Processed in 0.087424 second(s), 19 queries , Gzip On.

Powered by Discuz! X3.4

© 2001-2023 Discuz! Team.

快速回复 返回顶部 返回列表