当前位置:网站首页>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 .
边栏推荐
- 【性能测试】一文读懂Jmeter
- Thesis learning -- time series similarity query method based on extreme point characteristics
- Life planning (flag)
- Two years ago, the United States was reluctant to sell chips, but now there are mountains of chips begging China for help
- Activiti常見操作數據錶關系
- Div hidden in IE 67 shows blank problem IE 8 is normal
- [real case] how to deal with the failure of message consumption?
- Practice (9-12 Lectures)
- The cloud native programming challenge ended, and Alibaba cloud launched the first white paper on application liveliness technology in the field of cloud native
- SQL foundation 9 [grouping data]
猜你喜欢
Zephyr 学习笔记1,threads
Introduction to neural network (Part 2)
【Go基础】1 - Go Go Go
Ecole bio rushes to the scientific innovation board: the annual revenue is 330million. Honghui fund and Temasek are shareholders
What are the work contents of operation and maintenance engineers? Can you list it in detail?
How to use MOS tube to realize the anti reverse connection circuit of power supply
Xcode 14之大变化详细介绍
[network security] what is emergency response? What indicators should you pay attention to in emergency response?
How to send mail with Jianmu Ci
[real case] how to deal with the failure of message consumption?
随机推荐
PCIE知识点-010:PCIE 热插拔资料从哪获取
The text box displays the word (prompt text) by default, and the text disappears after clicking.
ZABBIX monitoring system custom monitoring content
[untitled] notice on holding "2022 traditional fermented food and modern brewing technology"
Blog stop statement
Routing decorator of tornado project
When JDBC connects to es query, is there a God who meets the following situation?
Take you to master the formatter of visual studio code
JVM中堆概念
弈柯莱生物冲刺科创板:年营收3.3亿 弘晖基金与淡马锡是股东
Distributed transaction management DTM: the little helper behind "buy buy buy"
The idea of implementing charts chart view in all swiftui versions (1.0-4.0) was born
Scanf read in data type symbol table
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-...)
Leetcode 146. LRU 缓存
MySQL中的文本處理函數整理,收藏速查
Common components of flask
果果带你写链表,小学生看了都说好
Heap concept in JVM
2022 - 021arts: début du deuxième semestre