本文最后更新于:几秒前
题目要求
编程模拟电梯的运行,条件是电梯面板没有14层和18层,用户输入要去的楼层,输出实际到达的楼层(物理高度的楼层)
可以自己设定楼层高度等条件。
作业要求:
1、进一步完善流程图并提交到课堂派
2、编程实现,即提交python代码到课堂派(注意提交的代码文件格式为txt)
流程图
代码
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
| """ 假设本楼最高可到30层,最低可到地下三层(-3层),以输入0为循环的跳出条件 """
def ReachedFloor(elevator): if elevator > 14 and elevator < 18: elevator -= 1 elif elevator > 18: elevator -= 2 else: pass return elevator
def OutOfRange(elevator): if elevator==14 or elevator==18: print("The elevator doesn't have this floor! Please retry!") elif elevator>30: print("The highest floor is 30, Please input the correct floor!") elif elevator<-3: print("The lowest floor is -3, Please input the correct floor!") else:return False return True
if __name__ == '__main__': while True: try: elevator=int(input("Please input the number of floor:\n")) except: print("Please input an integer to represent the floor!") continue else: if elevator==0: print("byebye!") break elif OutOfRange(elevator): continue else: print("You successfully reached floor:"+str(ReachedFloor(elevator)))
|