python二级练习(7)

栏目: Python · 发布时间: 8年前

内容简介:python二级练习(7)

7. 猜数游戏。预设一个0~9之间的整数,让用户猜一猜并输入所猜的数,如果大于预期的数,显示“太大”;小于预设的数,显示“太小”,如此循环,直到猜中该数,显示“恭喜!你猜中了!”。

#python 3.6
#蔡军生 
#http://blog.csdn.net/caimouse/article/details/51749579
#
import random

num = random.randint(0,9)
while True:
    yournum = int(input('请输入你猜的数(0~9):'))
    if yournum == num:
        print('恭喜!你猜中了!')
        break
    elif yournum < num:
        print('太小')
    else:
        print('太大')

输出结果如下:

请输入你猜的数(0~9):3

太小

请输入你猜的数(0~9):4

恭喜!你猜中了!

深入浅出Matplotlib

https://edu.csdn.net/course/detail/6859

深入浅出Numpy

http://edu.csdn.net/course/detail/6149

Python游戏开发入门

http://edu.csdn.net/course/detail/5690


以上就是本文的全部内容,希望本文的内容对大家的学习或者工作能带来一定的帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

Fluent Python

Fluent Python

Luciano Ramalho / O'Reilly Media / 2015-8-20 / USD 39.99

Learn how to write idiomatic, effective Python code by leveraging its best features. Python's simplicity quickly lets you become productive with it, but this often means you aren’t using everything th......一起来看看 《Fluent Python》 这本书的介绍吧!

在线进制转换器
在线进制转换器

各进制数互转换器

XML、JSON 在线转换
XML、JSON 在线转换

在线XML、JSON转换工具

正则表达式在线测试
正则表达式在线测试

正则表达式在线测试