当前位置:网站首页>Figure guessing game
Figure guessing game
2022-07-04 07:43:00 【Beauty of algorithm and programming】
0 introduction
stay python in , You can write some small programs by yourself , Play some interesting games .
1 problem
Guess the number game :
1. The system randomly generates a 1~100 The number of ;
2. All users have 5 Second chance to guess ;
3. If the user guesses that the number is greater than the number given by the system , Print "too big"
4. If the user guesses that the number is less than the number given by the system , Print "too small"
5. If the number guessed by the user is equal to the number given by the system , Print " Congratulations on winning ", And exit the loop
2 Method
without doubt , This problem needs to be solved by using cycles . First you need to use “from random import*” To randomly generate a 1-100 The number of . In circulation , Namely “too big”,“too small” as well as “ Congratulations on winning ”. There are only five cycles at most .
3 Experimental results and discussion
Through the experiment 、 Practice has proved that the proposed method is effective , Is able to solve the problem raised at the beginning .
Code list 1
from random import* num=randint(1,101) for i in range(5): a=eval(input(' Please enter a number :')) if a>num: print('too big') if a<num: print('too small') if a==num: print(' Congratulations on winning ') break |
4 Conclusion
For this use python Write an interesting little program , We use the loop structure and “from random import*” To randomly generate a 1-100 Number guessing game . The loop structure can repeat programs that need to be executed many times , This greatly reduces the workload , Saving manpower , But when writing a loop program , You need to remember to write an exit program , So as not to keep cycling .
边栏推荐
- L1-021 important words three times (5 points)
- L1-023 output gplt (20 points)
- [kubernetes series] kubesphere is installed on kubernetes
- Distributed transaction management DTM: the little helper behind "buy buy buy"
- BUUCTF(4)
- How to use MOS tube to realize the anti reverse connection circuit of power supply
- A real penetration test
- Preliminary study on temporal database incluxdb 2.2
- OKR vs. KPI 一次搞清楚这两大概念!
- zabbix监控系统邮件报警配置
猜你喜欢
墨者学院-PHPMailer远程命令执行漏洞溯源
Zephyr 学习笔记1,threads
System architecture design of circle of friends
Distributed transaction management DTM: the little helper behind "buy buy buy"
墨者学院-Webmin未经身份验证的远程代码执行
flask-sqlalchemy 循环引用
Experience installing VMware esxi 6.7 under VMware Workstation 16
Preliminary study on temporal database incluxdb 2.2
It's healthy to drink medicinal wine like this. Are you drinking it right
In the era of low code development, is it still needed?
随机推荐
[C language] open the door of C
Technical experts from large factories: common thinking models in architecture design
Experience installing VMware esxi 6.7 under VMware Workstation 16
In the era of low code development, is it still needed?
Introduction to neural network (Part 2)
L1-022 odd even split (10 points)
Two years ago, the United States was reluctant to sell chips, but now there are mountains of chips begging China for help
提升复杂场景三维重建精度 | 基于PaddleSeg分割无人机遥感影像
How does dataframe calculate the average value of each row as another column
Xcode 14之大变化详细介绍
Activiti常见操作数据表关系
论文学习——基于极值点特征的时间序列相似性查询方法
SQL注入测试工具之Sqli-labs下载安装重置数据库报错解决办法之一(#0{main}thrown in D:\Software\phpstudy_pro\WWW\sqli-labs-……)
Zephyr 学习笔记2,Scheduling
L1-027 rental (20 points)
Distributed transaction management DTM: the little helper behind "buy buy buy"
L1-023 output gplt (20 points)
socket inet_ pton() inet_ Ntop() function (a new network address translation function, which converts the expression format and numerical format to each other. The old ones are inet_aton(), INET_ ntoa
Zephyr 學習筆記2,Scheduling
墨者学院-Webmin未经身份验证的远程代码执行