你好,我是jpose75,我的代码有问题,现在该怎么办:

-4 投票
0 回答
29 浏览
提问于 2025-04-12 03:24

你是个电视迷,不喜欢一次只看一个频道。你总是在不同的频道之间切换,像在“刷”频道一样。你的狗试图咬遥控器,不幸的是把它弄坏了。现在你只能用两个按钮来换频道:一个是切换到下一个频道,另一个是切换到上一个频道。

你的电视有100个频道,编号从0到99,而且是循环的,也就是说,如果你在频道99上按下一个按钮,就会跳到频道0,反之亦然。

任务

你需要写一个程序,接收两个数字,每个数字在一行:目标频道和当前频道。程序要输出从当前频道到目标频道所需按按钮的最少次数,并说明是“X次向上”还是“Y次向下”,取决于哪个更少。(X和Y是按按钮的次数)。为了简化这个练习,X和Y永远不会相等。

代码:

x = int(input())
y = int(input())
z = (y - x)
w = (x - y)
ciclop = (99 - x) + y + 1 #si el ciclo no supera 99
ciclon = x + (99 - y) + 1 #si el ciclo supera 99
#print(ciclop, ciclon)

if y > x and z < 50:
  print(abs(100 - ciclon), "veces abajo")
elif y > x and z > 50:
  print(abs(ciclon), "veces arriba")
elif x > y and w > 95:
  print(ciclop, "veces abajo")
elif x > y and z < 50:
  print(abs(ciclon - 100), "veces arriba")
elif x > y and z > 50:
  print(abs(100 - ciclon), "veces arriba")]

0 个回答

暂无回答

撰写回答