利用python电梯显示程序编码

1.想开发建筑物电梯的运行画面(Display)程序。这个节目是建筑物的地面(1,2,3,...)和地下(-1,-2,-3,...)不管楼层数多少,可以适用于所有建筑物使用,但是假设所有建筑物都存在大厅层(0层)。

2.输入用户想去的层(targetFloor)的话,比现在层(currentFloor)高的话调用goUpfloor函数,低的话调用goDownfloor函数,和现在层一样的话输入另外一层。(使用下一页给的代码)

3.电梯移动时,每层在画面上连续显示几层,告知到达想去的楼层时到达了。
可以使用 continue, break, return, if ,elif,else,while, for, global ,def print.int,input,true,false函数
显示为以下。 请输入想要到达层数(运行停止 -100输入): 3
现在层数1 .
现在层数2 .
现在层数3.
3 层以到达. 请慢走 .
请输入想要到达层数(运行停止 -100输入): -2 现在层数 3 .
现在层数 2
现在层数 1 .
现在层数 0 .
现在层数 -1 .
现在层数 -2.
-2 层已到达. 请慢走.
请输入想要到达层数(运行停止-100输入): -2 层以外的层数输入.
请输入想要到达层数(运行停止-100输入): 0 现在层数-2 .
现在层数-1 .
现在层数 0.
0 层已到达. 请慢走.
请输入想要到达层数(运行停止-100输入): -100

提示利用 def goDownfloor(current, target): for floor in
def goUpfloor(current, target): for floor in
currentFloor = 1 while(True):
targetFloor = int(input('想要到达的楼层(运行停止 -100): '))
if targetFloor == -100: break
else:

def goDownfloor(current,target):
    print(f"现在层数{current}")
    while current>target:
        current -= 1
        print(f"现在层数{current}")
    print(f"{current}层已到达,请慢走。")
    return current

def goUpfloor(current,target):
    print(f"现在层数{current}")
    while current<target:
        current += 1
        print(f"现在层数{current}")
    print(f"{current}层已到达,请慢走。")
    return current

currentFloor = 1
while True:
    targetFloor = int(input("请输入想要到达的楼层(运行停止-100):"))
    if targetFloor == -100:
        break
    else:
        if targetFloor > currentFloor:
            currentFloor = goUpfloor(currentFloor, targetFloor)
        elif targetFloor < currentFloor:
            currentFloor = goDownfloor(currentFloor, targetFloor)
        else:
            print(f"现在层数{currentFloor},请输入另外一层")