您不能選擇超過 %s 個話題 話題必須以字母或數字為開頭,可包含連接號 ('-') 且最長為 35 個字
此存儲庫已封存,您能瀏覽檔案及複製此存儲庫,但不能推送、建立問題及拉取請求。

05-airports.py 629 B

6 年之前
6 年之前
6 年之前
123456789101112131415161718192021222324252627282930
  1. import sys
  2. def build_airport_dict():
  3. result = dict()
  4. file = open("airports.txt", "r")
  5. contents = file.read()
  6. lines = contents.splitlines()
  7. for line in lines:
  8. words = line.split(" ", maxsplit=1)
  9. assert len(words) == 2
  10. code = words[0]
  11. name = words[1].strip()
  12. result[code] = name
  13. return result
  14. def main():
  15. if len(sys.argv) < 2:
  16. sys.exit("Not enough arguments")
  17. airport_dict = build_airport_dict()
  18. code = sys.argv[1]
  19. if code not in airport_dict:
  20. sys.exit("Code not found")
  21. result = airport_dict[code]
  22. print(result)
  23. main()