[关闭]
@StarSky 2017-07-12T06:23:37.000000Z 字数 1090 阅读 1155

2017-07-11 1 TO 3

Puzzle


begin-> http://www.pythonchallenge.com/pc/def/0.html

  1. # -*- coding: utf-8 -*-
  2. """1"""
  3. """http://www.pythonchallenge.com/pc/def/map.html"""
  4. char_string = 'map'
  5. new_string = ''
  6. for char in char_string:
  7. if char != '.' and char != ' ':
  8. if ord(char) == 121:
  9. new_string += 'a'
  10. elif ord(char) == 122:
  11. new_string += 'b'
  12. else:
  13. charcode = ord(char) + 2
  14. new_char = chr(charcode)
  15. new_string += new_char
  16. else:
  17. new_string += char
  18. print(new_string)
  19. """2"""
  20. """http://www.pythonchallenge.com/pc/def/ocr.html"""
  21. dict_test = {}
  22. with open('/Users/saber/Desktop/untitled', 'r') as f:
  23. for line in f.readlines():
  24. for char in line:
  25. if char not in dict_test:
  26. dict_test[char] = 1
  27. else:
  28. dict_test[char] += 1
  29. dict_test = sorted(dict_test.items(), lambda x, y: cmp(int(x[1]), int(y[1])))
  30. print("pause")
  31. """3"""
  32. """http://www.pythonchallenge.com/pc/def/equality.html"""
  33. with open('/Users/saber/Desktop/untitled', 'r') as f:
  34. new_string = ''
  35. for line in f.readlines():
  36. for char in line:
  37. if char.isupper():
  38. if 0 < len(new_string) < 4:
  39. new_string += char
  40. elif 5 <= len(new_string) <= 7:
  41. new_string += char
  42. else:
  43. new_string = ''
  44. else:
  45. if len(new_string) == 4:
  46. new_string += char
  47. elif len(new_string) == 8:
  48. print new_string[4]
  49. new_string = ''
  50. else:
  51. new_string = char
添加新批注
在作者公开此批注前,只有你和作者可见。
回复批注