当前位置:网站首页>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 .
边栏推荐
- What determines vacuum permittivity and vacuum permeability? Why do these two physical quantities exist?
- Introduction to sap commerce cloud B2B organization function
- L1-028 judging prime number (10 points)
- Rhcsa day 3
- 【性能测试】一文读懂Jmeter
- One of the general document service practice series
- [network security] what is emergency response? What indicators should you pay attention to in emergency response?
- 提升复杂场景三维重建精度 | 基于PaddleSeg分割无人机遥感影像
- 21 examples of strategic goals to promote the rapid development of your company
- [untitled] notice on holding "2022 traditional fermented food and modern brewing technology"
猜你喜欢

MySQL中的文本处理函数整理,收藏速查

Introduction to sap commerce cloud B2B organization function

论文学习——基于极值点特征的时间序列相似性查询方法

zabbix監控系統自定義監控內容

Rhcsa day 3

L2-013 red alarm (C language) and relevant knowledge of parallel search

Advanced MySQL: Basics (5-8 Lectures)

The idea of implementing charts chart view in all swiftui versions (1.0-4.0) was born

JVM -- class loading process and runtime data area

The cloud native programming challenge ended, and Alibaba cloud launched the first white paper on application liveliness technology in the field of cloud native
随机推荐
window上用.bat文件启动项目
The frost peel off the purple dragon scale, and the xiariba people will talk about database SQL optimization and the principle of indexing (primary / secondary / clustered / non clustered)
Introduction to sap commerce cloud B2B organization function
论文学习——基于极值点特征的时间序列相似性查询方法
Text processing function sorting in mysql, quick search of collection
One of the general document service practice series
zabbix监控系统邮件报警配置
[FreeRTOS] FreeRTOS learning notes (7) - handwritten FreeRTOS two-way linked list / source code analysis
大学阶段总结
Guoguo took you to write a linked list, and the primary school students said it was good after reading it
【性能测试】一文读懂Jmeter
Sqli labs download, installation and reset of SQL injection test tool one of the solutions to the database error (# 0{main}throw in d:\software\phpstudy_pro\www\sqli labs-...)
Node foundation ~ node operation
This monitoring system can monitor the turnover intention and fishing all, and the product page has 404 after the dispute appears
[kubernetes series] kubesphere is installed on kubernetes
With excellent strength, wangchain technology, together with IBM and Huawei, has entered the annual contribution list of "super ledger"!
Zephyr Learning note 2, Scheduling
OKR vs. KPI figure out these two concepts at once!
Advanced MySQL: Basics (5-8 Lectures)
Heap concept in JVM