当前位置:网站首页>The application of for loop and if judgment statement
The application of for loop and if judgment statement
2022-07-25 07:21:00 【Beauty of algorithm and programming】
0 introduction
stay python in , We learned and mastered for Circulation and if The judgment of the , They can help us solve some math problems around us .
1 problem
Output the number of all daffodils .
2 Method
It needs to be used twice for Cycle design . for the first time for The purpose of circulation is to make i Take all three digits , The second time is right i Traversal cycle , Loop out each traversal j use sum Proceed incrementally , And then determine sum Whether the value of is the same as i equal , Finally, the number of daffodils is output .
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
| for i in range(100,1000): sum = 0 for j in str(i): sum += int(j)**3 if sum ==i: print(i) |
4 Conclusion
utilize for Circulation and if The judgment of the , Make us to for Circular statements and if The use of judgment sentences is more skilled .
边栏推荐
- Leetcode118. Yanghui triangle
- What if Oracle 19C migration encounters large lob tables?
- Summary of differences between data submission type request payload and form data
- list的模拟实现
- 各位老板 问一下 就是我们mysql cdc保存的是配置数据 然后kafka里面堆积的有历史
- leetcode刷题:动态规划06(整数拆分)
- "Wei Lai Cup" 2022 Niuke summer multi school training camp 1 supplementary problem solution (incomplete)
- knapsack problem
- 新库上线| CnOpenDataA股上市公司股东信息数据
- First, how about qifujin
猜你喜欢

Leetcode118. Yanghui triangle

Lidar construction map (overlay grid construction map)

Talk about practice, do solid work, and become practical: tour the digitalized land of China

vulnhub CyberSploit: 1

QT学习日记20——飞机大战项目

BOM overview

集群聊天服务器:项目问题汇总

Leave the factory and sell insurance

MATLAB自编程系列(1)---角分布函数

30 times performance improvement -- implementation of MyTT index library based on dolphin DB
随机推荐
Servlet常用类剖析
30 times performance improvement -- implementation of MyTT index library based on dolphin DB
华为无线设备配置WAPI-证书安全策略
一日千里,追风逐月 | 深势科技发布极致加速版分子对接引擎Uni-Docking
[semidrive source code analysis] [drive bringup] 39 - touch panel touch screen debugging
paddlepaddle 34 调整模型的layer结构与forward流程(实现layer的增删改与forward的修改)
Octopus network community call 1 starts Octopus Dao construction
JS cannot get content disposition in headers
[computer explanation] NVIDIA released geforce RTX Super Series graphics cards, and the benefits of game players are coming!
[cloud native] the ribbon is no longer used at the bottom of openfeign, which started in 2020.0.x
各位老板 问一下 就是我们mysql cdc保存的是配置数据 然后kafka里面堆积的有历史
10 key points and 5 measures for good project management
批量导入数据,一直提示 “失败原因:SQL解析失败:解析文件失败::null”怎么回事?
Wei Lai: what is the difference between multithreaded join and detach?
【云原生】原来2020.0.X版本开始的OpenFeign底层不再使用Ribbon了
Analysis of common classes of Servlet
Leetcode skimming: dynamic programming 06 (integer splitting)
New tea, start "fighting in groups"
Can interface debugging still play like this?
Paddlepaddle 34 adjust the layer structure and forward process of the model (realize the addition, deletion, modification and forward modification of the layer)