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.

29 regels
970 B

  1. #!/usr/bin/env python3
  2. #title :8-4.py
  3. #description :Opdracht 8.4 - File & dict
  4. #author :Marcel Haazen
  5. #email :marcel@haazen.xyz
  6. #date :28-10-2019 - 13:20
  7. #version :0.1
  8. #usage :python3 8-4.py
  9. #notes :
  10. #python_version :3.7.3
  11. #==============================================================================
  12. def ticker():
  13. filename = 'tickers.txt'
  14. tickers = {}
  15. with open(filename) as fh:
  16. for line in fh:
  17. company, ticker = line.strip().split(':', 1)
  18. tickers[company] = ticker.strip()
  19. return tickers
  20. try:
  21. comp = str(input("Enter Company name: ")).upper()
  22. print((ticker())[comp])
  23. except KeyError as identifier:
  24. print("Dit bedrijf in onbekend.")
  25. try:
  26. tick = comp = str(input("Enter Ticker symbol: ")).upper()
  27. print([key for key in ticker().items() if key[1] == tick][0][0])
  28. except StopIteration as identifier:
  29. print("Dit bedrijf in onbekend.")