python二级练习(7)

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

内容简介: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


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

查看所有标签

猜你喜欢:

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

Rationality for Mortals

Rationality for Mortals

Gerd Gigerenzer / Oxford University Press, USA / 2008-05-02 / USD 65.00

Gerd Gigerenzer's influential work examines the rationality of individuals not from the perspective of logic or probability, but from the point of view of adaptation to the real world of human behavio......一起来看看 《Rationality for Mortals》 这本书的介绍吧!

JSON 在线解析
JSON 在线解析

在线 JSON 格式化工具

SHA 加密
SHA 加密

SHA 加密工具