Python学习笔记524

简介: Python 练习实例

题目:时间函数举例4,一个猜数游戏,判断一个人反应快慢。

程序分析:无。

程序源代码:

实例(Python 2.0+)

#!/usr/bin/python# -*- coding: UTF-8 -*-if__name__ == '__main__':     importtime    importrandom         play_it = raw_input('do you want to play it.(\'y\' or \'n\')')    whileplay_it == 'y':         c = raw_input('input a character:\n')        i = random.randint(0,2**32) % 100        print'please input number you guess:\n'        start = time.clock()        a = time.time()        guess = int(raw_input('input your guess:\n'))        whileguess != i:             ifguess > i:                 print'please input a little smaller'                guess = int(raw_input('input your guess:\n'))            else:                 print'please input a little bigger'                guess = int(raw_input('input your guess:\n'))        end = time.clock()        b = time.time()        var = (end - start) / 18.2        printvar        # print 'It took you %6.3 seconds' % time.difftime(b,a))        ifvar < 15:             print'you are very clever!'        elifvar < 25:             print'you are normal!'        else:             print'you are stupid!'        print'Congradulations'        print'The number you guess is %d' % i        play_it = raw_input('do you want to play it.')

以上实例输出结果为:

do you want to play it.('y'or'n')y

input a character:

5

please input number you guess:


input your guess:

60

……

please input a little bigger

input your guess:

29

please input a little smaller

input your guess:

28

3.81868131868e-05

you are very clever!

Congradulations

The number you guess is28

do you want to play it.

相关文章
|
网络协议 Java Linux
PyAV学习笔记(一):PyAV简介、安装、基础操作、python获取RTSP(海康)的各种时间戳(rtp、dts、pts)
本文介绍了PyAV库,它是FFmpeg的Python绑定,提供了底层库的全部功能和控制。文章详细讲解了PyAV的安装过程,包括在Windows、Linux和ARM平台上的安装步骤,以及安装中可能遇到的错误和解决方法。此外,还解释了时间戳的概念,包括RTP、NTP、PTS和DTS,并提供了Python代码示例,展示如何获取RTSP流中的各种时间戳。最后,文章还提供了一些附录,包括Python通过NTP同步获取时间的方法和使用PyAV访问网络视频流的技巧。
3306 4
PyAV学习笔记(一):PyAV简介、安装、基础操作、python获取RTSP(海康)的各种时间戳(rtp、dts、pts)
|
Python
Socket学习笔记(二):python通过socket实现客户端到服务器端的图片传输
使用Python的socket库实现客户端到服务器端的图片传输,包括客户端和服务器端的代码实现,以及传输结果的展示。
665 3
Socket学习笔记(二):python通过socket实现客户端到服务器端的图片传输
|
JSON 数据格式 Python
Socket学习笔记(一):python通过socket实现客户端到服务器端的文件传输
本文介绍了如何使用Python的socket模块实现客户端到服务器端的文件传输,包括客户端发送文件信息和内容,服务器端接收并保存文件的完整过程。
662 1
Socket学习笔记(一):python通过socket实现客户端到服务器端的文件传输
|
关系型数据库 MySQL 数据库
Mysql学习笔记(四):Python与Mysql交互--实现增删改查
如何使用Python与MySQL数据库进行交互,实现增删改查等基本操作的教程。
206 1
|
Ubuntu Linux Python
Ubuntu学习笔记(六):ubuntu切换Anaconda和系统自带Python
本文介绍了在Ubuntu系统中切换Anaconda和系统自带Python的方法。方法1涉及编辑~/.bashrc和/etc/profile文件,更新Anaconda的路径。方法2提供了详细的步骤指导,帮助用户在Anaconda和系统自带Python之间进行切换。
565 1
|
索引 Python
Python学习笔记编程小哥令狐~持续更新、、、(上)
Python学习笔记编程小哥令狐~持续更新、、、(上)
168 2
|
索引 Python
【免费分享编程笔记】Python学习笔记(一)
【免费分享编程笔记】Python学习笔记(一)
109 1
|
存储 Python
Python学习笔记编程小哥令狐~持续更新、、、 (下)
Python学习笔记编程小哥令狐~持续更新、、、 (下)
117 1
|
Java 编译器 Go
Python学习笔记--- day01计算机基础和环境搭建(一)
Python学习笔记--- day01计算机基础和环境搭建(一)
215 2
|
存储 Python
【免费分享编程笔记】Python学习笔记(二)
【免费分享编程笔记】Python学习笔记(二)
152 0
【免费分享编程笔记】Python学习笔记(二)

推荐镜像

更多