Advertisement
FranzVuttke

dict_if_param

Jan 19th, 2023 (edited)
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.96 KB | None | 0 0
  1. # https://www.facebook.com/groups/2616981278627207/posts/3463307970661196/?#__cft__[0]=AZVmZFrUsYPKRacZF8RpXemuyUKpFucuEkG2Duyq0ERwNHOHx492MdyhOkjflolibNVmTukTtOPRRCbwDIvvIdl62CNBVyev3opFIzpjj9tn8DHnjPdOLKSWiPs#wYwyB6UEridkyreMJ_40HRpLntgGN&__tn__=%2CO%2CP-R
  2.  
  3. #!/usr/bin/python
  4. #!/usr/env/python
  5.  
  6. #
  7. # file with items to choose
  8. #
  9. # scientific_materials.txt
  10. # struct:
  11. # mat:Math
  12. # phy:Physics
  13. # physics:Physics
  14.  
  15.  
  16. FILE_NAME = "scientific_materials.txt"
  17.  
  18. def main(args):
  19.     # creating options dictionary
  20.     items = {}
  21.     with open(FILE_NAME) as file:
  22.         for line in file:
  23.             if line.startswith("#"):
  24.                 continue
  25.             line = line.split("\n")[0]
  26.             items[line.split(":")[0]] = line.split(":")[1]
  27.  
  28.     answ = input("Enter what you are interested in: ").lower()
  29.     print("Choosen: {}".format(items.get(answ, "nothing")))
  30.    
  31.    
  32.  
  33.  
  34. if __name__ == "__main__":
  35.     import sys
  36.     sys.exit(main(sys.argv))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement