You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
This repo is archived. You can view files and clone it, but cannot push or open issues/pull-requests.
 
 
 
 
 
 

50 lines
836 B

  1. import sys
  2. def lire_code():
  3. if len(sys.argv) < 2:
  4. print(
  5. "Pas assez d'arguments",
  6. file=sys.stderr
  7. )
  8. sys.exit(1)
  9. return sys.argv[1].upper()
  10. def fabrique_dico():
  11. dico = dict()
  12. file = open("airports.txt", "r")
  13. contenu = file.read()
  14. lignes = contenu.splitlines()
  15. for ligne in lignes:
  16. code = ligne[0:3]
  17. nom = ligne[4:]
  18. dico[code] = nom
  19. return dico
  20. def trouve_code(code, dico):
  21. if code in dico:
  22. return dico[code]
  23. def affiche_erreur(code):
  24. print(
  25. "Code:", code,
  26. "non trouvé",
  27. file=sys.stderr
  28. )
  29. sys.exit(2)
  30. def main():
  31. dico = fabrique_dico()
  32. code = lire_code()
  33. nom = trouve_code(code, dico)
  34. if nom:
  35. print(nom)
  36. else:
  37. affiche_erreur(code)
  38. main()