Python猜字游戏
来源:互联网 发布:照片歌曲制作软件 编辑:程序博客网 时间:2024/06/07 20:48
有一个猜字游戏,现在的情况是,计算机随机生成一个整数,这个整数的区间我们事先给定,这里假定数在0到100之间,然后我们猜字,当猜的数大于生成的整数时,输出“Your answer is too large.”,当猜的数小于生成的整数时,输出“Your answer is too small.”,猜中数字输出“BINGO!!”,结束游戏,下面是python的脚本,以及测试情况:
def main():import randoma=random.randint(0,100)print('Guess what i think?')b=int(input('Enter a number:'))while(b!=a):if(b<a):print('Your answer is too small.')elif(b>a):print('Your answer is too large.')b=int(input('Enter a number:'))print('BINGO!!')
测试结果:
>>> main()
Guess what i think?
Enter a number:0
Your answer is too small.
Enter a number:100
Your answer is too large.
Enter a number:50
Your answer is too large.
Enter a number:25
Your answer is too small.
Enter a number:37
Your answer is too small.
Enter a number:43
Your answer is too large.
Enter a number:40
Your answer is too small.
Enter a number:42
Your answer is too large.
Enter a number:41
BINGO!!
0 0
- Python猜字游戏
- Python猜字游戏
- Python初学的猜字游戏
- python猜数字游戏
- python-猜数字游戏
- Python猜数字游戏
- python 猜数字游戏
- python猜数字游戏
- python猜数字游戏
- python猜数字游戏
- python猜数字游戏
- Python学习 猜数字游戏
- python破解猜数游戏
- python 版猜数字游戏
- python实现猜数字游戏
- python版猜数字游戏
- 猜数字游戏--基于python
- python游戏
- angularjs中指令的scope作用域
- g++编译警告原因分析Wunused-but-set-variable
- Echarts 后台交互(折线图)
- 下拉刷新控件实现(尤其headview如何实现隐藏和下拉显示)
- JQ系统函数 - 动画
- Python猜字游戏
- 《图解HTTP》笔记——与HTTP协作的Web服务器(第5章)
- 关于eclipse总是building workspace问题
- C++学习笔记(一) 基础语法 —参考阿发你好
- Gradle plugin和AS版本不兼容的报错
- OpenGL编程指南-光照
- AJAX GetAndPost请求的完整封装
- MyBatis一对多关系映射
- jsp、freemarker、velocity