1.Collatz 序列
编写一个程序,打印给定数字的 Collatz 序列,直到达到 1。
Rule: If the number is even: n=n/2 If the number is odd: n=3n+1.
def even_odd(no): while no>0: num=no%10 if num%2==0: even=num/2 print(even) else: odd=3*num+1 print(odd) no=no//10 no=int(input("Enter the number:")) even_odd(no)
Enter the number:12345 16 2.0 10 1.0 4
*2.找出一个数中所有数字都相等
*
no = int(input("Enter no. ")) equal = no%10 while no>0: rem = no%10 if rem == equal: equal=rem else: print("All Numbers are not equal") break no//=10 else: print("All numbers are equal")
Enter no. 1234 All Numbers are not equal Enter no. 4444 All numbers are equal
拼图程序:
1.在 4 小时内,马总共走了 4 英尺,因为它在第一小时跑 1 英尺,第二小时跑 2 英尺,第三小时跑 3 英尺,第四小时跑 4 英尺。
如果马需要走 12 步才能走 1 英尺,并且在 4 小时内总共跑了 10 英尺,那么这匹马的总步数是:
10 英尺×每英尺12 步=120 步。
4 小时内,马走了 120 步,走了 10 英尺。
total = 0 steps = 12 ft = 1 while ft <pre class="brush:php;toolbar:false">120
2.每天,青蛙会爬升 1 英尺,但在一天结束时会向后滑落 0.5 英尺。
因此,每天的增益为 1−0.5=0.5 英尺。
然而,当青蛙达到或超过 30 英尺的那一天,它就不会再滑回来了。
找出青蛙需要多少天才能到达山顶。
height = 30 up = 1 down = 0.5 total = 0 days = 0 while total<height: total="total" up down days print> <pre class="brush:php;toolbar:false">60
3.如果时钟最初延迟 5 分钟,并且每小时延迟 5 分钟。
早上8点到下午1点会延误多少分钟。
morning = 8 afternoon = 13 difference = 5 late = 0 while difference>0: late = late + 5 difference-=1 print(late)
25
4.将铁路时间转换为正常时间,将正常时间转换为铁路时间。
铁路时间至正常时间:
15:09 - 3:09
正常时间至铁路时间:
3:09 - 15:09
time=float(input("Enter the time:")) if time <pre class="brush:php;toolbar:false">Enter the time:15.09 time: 3.09 Enter the time:3.09 time: 15.09
以上是日间循环和拼图节目的详细内容。更多信息请关注PHP中文网其他相关文章!

pythonisehybridmodelofcompilationand interpretation:1)thepythoninterspretercompilesourcececodeintoplatform- interpententbybytecode.2)thepytythonvirtualmachine(pvm)thenexecuteCutestestestesteSteSteSteSteSteSthisByTecode,BelancingEaseofuseWithPerformance。

pythonisbothinterpretedAndCompiled.1)它的compiledTobyTecodeForportabilityAcrosplatforms.2)bytecodeisthenInterpreted,允许fordingfordforderynamictynamictymictymictymictyandrapiddefupment,尽管Ititmaybeslowerthananeflowerthanancompiledcompiledlanguages。

在您的知识之际,而foroopsareideal insinAdvance中,而WhileLoopSareBetterForsituations则youneedtoloopuntilaconditionismet

ForboopSareSusedwhenthentheneMberofiterationsiskNownInAdvance,而WhileLoopSareSareDestrationsDepportonAcondition.1)ForloopSareIdealForiteratingOverSequencesLikelistSorarrays.2)whileLeleLooleSuitableApeableableableableableableforscenarioscenarioswhereTheLeTheLeTheLeTeLoopContinusunuesuntilaspecificiccificcificCondond

pythonisnotpuroly interpred; itosisehybridablectofbytecodecompilationandruntimeinterpretation.1)PythonCompiLessourceceCeceDintobyTecode,whitsthenexecececected bytybytybythepythepythepythonvirtirtualmachine(pvm).2)

concateNateListsinpythonwithTheSamelements,使用:1)operatototakeepduplicates,2)asettoremavelemavphicates,or3)listCompreanspearensionforcontroloverduplicates,每个methodhasdhasdifferentperferentperferentperforentperforentperforentperfortenceandordormplications。

pythonisanterpretedlanguage,offeringosofuseandflexibilitybutfacingperformancelanceLimitationsInCricapplications.1)drightingedlanguageslikeLikeLikeLikeLikeLikeLikeLikeThonexecuteline-by-line,允许ImmediaMediaMediaMediaMediaMediateFeedBackAndBackAndRapidPrototypiD.2)compiledLanguagesLanguagesLagagesLikagesLikec/c thresst

Useforloopswhenthenumberofiterationsisknowninadvance,andwhileloopswheniterationsdependonacondition.1)Forloopsareidealforsequenceslikelistsorranges.2)Whileloopssuitscenarioswheretheloopcontinuesuntilaspecificconditionismet,usefulforuserinputsoralgorit


热AI工具

Undresser.AI Undress
人工智能驱动的应用程序,用于创建逼真的裸体照片

AI Clothes Remover
用于从照片中去除衣服的在线人工智能工具。

Undress AI Tool
免费脱衣服图片

Clothoff.io
AI脱衣机

Video Face Swap
使用我们完全免费的人工智能换脸工具轻松在任何视频中换脸!

热门文章

热工具

螳螂BT
Mantis是一个易于部署的基于Web的缺陷跟踪工具,用于帮助产品缺陷跟踪。它需要PHP、MySQL和一个Web服务器。请查看我们的演示和托管服务。

SublimeText3 英文版
推荐:为Win版本,支持代码提示!

MinGW - 适用于 Windows 的极简 GNU
这个项目正在迁移到osdn.net/projects/mingw的过程中,你可以继续在那里关注我们。MinGW:GNU编译器集合(GCC)的本地Windows移植版本,可自由分发的导入库和用于构建本地Windows应用程序的头文件;包括对MSVC运行时的扩展,以支持C99功能。MinGW的所有软件都可以在64位Windows平台上运行。

DVWA
Damn Vulnerable Web App (DVWA) 是一个PHP/MySQL的Web应用程序,非常容易受到攻击。它的主要目标是成为安全专业人员在合法环境中测试自己的技能和工具的辅助工具,帮助Web开发人员更好地理解保护Web应用程序的过程,并帮助教师/学生在课堂环境中教授/学习Web应用程序安全。DVWA的目标是通过简单直接的界面练习一些最常见的Web漏洞,难度各不相同。请注意,该软件中

EditPlus 中文破解版
体积小,语法高亮,不支持代码提示功能