本站资源收集于互联网,不提供软件存储服务,每天免费更新优质的软件以及学习资源!

日间循环和拼图节目

网络教程 app 1℃

日间循环和拼图节目

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/2print(even) else:odd=3*num+1print(odd) no=no//10no=int(input("enter the number:"))even_odd(no)

enter the number:12345162.0101.04

*2.找出一个数中所有数字都相等
*

no = int(input("enter no. ")) equal = no%10while 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. 1234all numbers are not equalenter no. 4444all numbers are equal

拼图程序:

1.在 4 小时内,马总共走了 4 英尺,因为它在第一小时跑 1 英尺,第二小时跑 2 英尺,第三小时跑 3 英尺,第四小时跑 4 英尺。
如果马需要 12 步才能覆盖 1 英尺,并且在 4 小时内总共跑了 10 英尺,那么这匹马的总步数是:

10 英尺×每英尺12 步=120 步。

4 小时内,马走了 120 步,走了 10 英尺。

total = 0steps = 12ft = 1while ft<=4: total = total + steps*ft ft+=1print(total)

120

2.每天,青蛙会爬升 1 英尺,但在一天结束时会向后滑落 0.5 英尺。
因此,每天的收益为 1−0.5=0.5 英尺。
然而,当青蛙到达或超过 30 英尺的那一天,它就不会再滑回来了。
找出青蛙需要多少天才能到达山顶。

height = 30up = 1down = 0.5total = 0days = 0while total<height: total = total + up – down days+=1print(days)

60

3.如果时钟最初延迟 5 分钟,并且每小时延迟 5 分钟。
早上8点到下午1点会延误多少分钟。

morning = 8afternoon = 13difference = 5late = 0while difference>0: late = late + 5 difference-=1print(late)

25

4.将铁路时间转换为正常时间,将正常时间转换为铁路时间。
铁路时间至正常时间:
15:09 – 3:09
正常时间与铁路时间:
3:09 – 15:09

time=float(input("enter the time:"))if time<=12: calculate_time=time+12 print("time:",calculate_time)else: calculate_time=12-time print("time:",round(-calculate_time,2))

Enter the time:15.09time: 3.09Enter the time:3.09time: 15.09

以上就是日间循环和拼图节目的详细内容,更多请关注范的资源库其它相关文章!

转载请注明:范的资源库 » 日间循环和拼图节目

喜欢 (0)