張瑋珊的學習歷程 - 111-1 大數據分析 - 2Python 程式練習:搭電梯 |
|
|
2Python 程式練習:搭電梯資料來源:https://medium.com/@mingjunlu/simple-elevator-simulator-in-python-6ff0c98a3ae6 current_floor = 5 while True: target_floor = input('您現在在 ' + str(current_floor) + ' 樓。請問要去哪一樓?\n>>') try: target_floor = int(target_floor) except ValueError: print('格式錯誤,請輸入數字\n') continue if target_floor < 1 or target_floor > 7: print('請輸入介於 1-7 的整數\n') continue if target_floor == current_floor: continue elif target_floor < current_floor: print('電梯下樓') while target_floor < current_floor: print(current_floor) current_floor = current_floor - 1 sleep(0.5) print(current_floor) else: print('電梯上樓') while target_floor > current_floor: print(current_floor) current_floor = current_floor + 1 sleep(0.5) print(current_floor)
|
|
中華科技大學數位化學習歷程 - 意見反應 |