搜索
首页后端开发Python教程日间循环和拼图节目

Day - Looping and Puzzle program

1.Collat​​z 序列
编写一个程序,打印给定数字的 Collat​​z 序列,直到达到 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中文网其他相关文章!

声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
Python:深入研究汇编和解释Python:深入研究汇编和解释May 12, 2025 am 12:14 AM

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

Python是一种解释或编译语言,为什么重要?Python是一种解释或编译语言,为什么重要?May 12, 2025 am 12:09 AM

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

对于python中的循环时循环与循环:解释了关键差异对于python中的循环时循环与循环:解释了关键差异May 12, 2025 am 12:08 AM

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

循环时:实用指南循环时:实用指南May 12, 2025 am 12:07 AM

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

Python:它是真正的解释吗?揭穿神话Python:它是真正的解释吗?揭穿神话May 12, 2025 am 12:05 AM

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

与同一元素的Python串联列表与同一元素的Python串联列表May 11, 2025 am 12:08 AM

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

解释与编译语言:Python的位置解释与编译语言:Python的位置May 11, 2025 am 12:07 AM

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

循环时:您什么时候在Python中使用?循环时:您什么时候在Python中使用?May 11, 2025 am 12:05 AM

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

See all articles

热AI工具

Undresser.AI Undress

Undresser.AI Undress

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

AI Clothes Remover

AI Clothes Remover

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

Undress AI Tool

Undress AI Tool

免费脱衣服图片

Clothoff.io

Clothoff.io

AI脱衣机

Video Face Swap

Video Face Swap

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

热门文章

热工具

螳螂BT

螳螂BT

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

SublimeText3 英文版

SublimeText3 英文版

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

MinGW - 适用于 Windows 的极简 GNU

MinGW - 适用于 Windows 的极简 GNU

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

DVWA

DVWA

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

EditPlus 中文破解版

EditPlus 中文破解版

体积小,语法高亮,不支持代码提示功能