a.py 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. import os, argparse
  2. encoding = {"A": "rock", "B": "paper", "C": "scissors",
  3. "X": "rock", "Y": "paper", "Z": "scissors"}
  4. scoring = {"rock": 1, "paper": 2, "scissors": 3}
  5. beats = {"rock": "paper", "paper": "scissors", "scissors": "rock"}
  6. def throw_hands(me, them):
  7. if me == them:
  8. return 3
  9. if me == beats[them]:
  10. return 6
  11. else:
  12. return 0
  13. def solve_task(lines):
  14. score = 0
  15. for line in lines:
  16. them = encoding[line[0]]
  17. me = encoding[line[-1]]
  18. score += throw_hands(me, them) + scoring[me]
  19. print(f"Score: {score}")
  20. def read_lines(filename):
  21. lines = []
  22. with open(filename) as infile:
  23. for raw_line in infile:
  24. line = raw_line.rstrip()
  25. lines.append(line)
  26. return lines
  27. def parse_arguments():
  28. parser = argparse.ArgumentParser(description="Script that solves the case",epilog="Have a nice day!")
  29. parser.add_argument('filename', nargs='?', default="example.txt", help='Input file')
  30. args = parser.parse_args()
  31. return args
  32. def main():
  33. args = parse_arguments()
  34. lines = read_lines(args.filename)
  35. solve_task(lines)
  36. if __name__ == "__main__":
  37. main()