Discuss / Python / 第一题

第一题

Topic source

Kevin_No5

#1 Created at ... [Delete] [Delete and Lock User]

import os def enter(): now = os.path.abspath(".") while True: s = input() s = s.strip() if s == 'exit': print('exit success!') break elif s.startswith('cd'): fs = s.split() pre = os.path.join(now,fs[1]) if os.path.isdir(pre): now = pre else: print("can't cd into a file or Directory is not exist!") elif s.startswith('ls'): for x in os.listdir(now): print(x) else: print("error cmd. Ex: 'cd path'、'ls','exit' to end of the process!") 稍微做了点改动,dir修改ls

Kevin_No5

#2 Created at ... [Delete] [Delete and Lock User]

刚开始进入是当前目录; 可以操作: cd .. 返回上层 cd xxx 进入摸一个文件夹 ls 显示当前目录下的说有文件夹和文件 exit 退出


  • 1

Reply