answer.py 962 B

12345678910111213141516171819202122232425262728293031323334
  1. # This Python file uses the following encoding: utf-8
  2. # @author runhey
  3. # github https://github.com/runhey
  4. import csv
  5. from datetime import datetime
  6. from pathlib import Path
  7. def answer_one(question: str, options: list[str]) -> int:
  8. """
  9. 每一个问题有四个选项, 返回选项的序号(1、2、3、4)
  10. :param question:
  11. :param options:
  12. :return:
  13. """
  14. file = str(Path(__file__).parent / 'data.csv')
  15. with open(file, newline='', encoding='utf-8-sig') as csvfile:
  16. reader = csv.reader(csvfile)
  17. next(reader)
  18. for row in reader:
  19. if row[0] == question:
  20. return options.index(row[1]) + 1
  21. else:
  22. return 1
  23. if __name__ == "__main__":
  24. question = '以下式神中,手持折扇的是'
  25. options = ['生命上限', '鬼王', '荒川之主', '鬼王']
  26. start_time = datetime.now()
  27. print(answer_one(question, options))
  28. print(datetime.now() - start_time)