Advertisement
Guest User

Y2020D2DaveedDigs

a guest
Dec 4th, 2020
649
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.81 KB | None | 0 0
  1. passports = open("material.txt", "r").read().split("\n\n")
  2. passportsvalid = 0
  3.  
  4. for passport in passports:
  5. passwordvalid = True
  6. passport = passport.replace('\n', ' ')
  7. fieldlist = passport.split(' ')
  8. d = dict(f.split(":") for f in fieldlist)
  9. try:
  10. if(not 1920 <= int(d['byr']) <= 2002):
  11. passwordvalid = False
  12. continue
  13. if(not 2010 <= int(d['iyr']) <= 2020):
  14. passwordvalid = False
  15. continue
  16. if(not 2020 <= int(d['eyr']) <= 2030):
  17. passwordvalid = False
  18. continue
  19. if("cm" in d['hgt']):
  20. if(not 150 <= int(d['hgt'][:len(d['hgt'])-2]) <= 193):
  21. passwordvalid = False
  22. continue
  23. elif("in" in d['hgt']):
  24. if(not 59 <= int(d['hgt'][:len(d['hgt'])-2]) <= 76):
  25. passwordvalid = False
  26. continue
  27. if(not d['hcl'][0] == "#"):
  28. passwordvalid = False
  29. continue
  30. else:
  31. if(len(d['hcl'][1:]) == 6):
  32. try:
  33. isint = int(d['hcl'][1:],16)
  34. except:
  35. passwordvalid = False
  36. continue
  37. else:
  38. passwordvalid = False
  39. continue
  40. if(not d['ecl'] in "amb blu brn gry grn hzl oth".split()):
  41. passwordvalid = False
  42. continue
  43. if(not len(d['pid']) == 9):
  44. passwordvalid = False
  45. continue
  46. else:
  47. try:
  48. isint = int(d['pid'])
  49. except:
  50. passwordvalid = False
  51. continue
  52. passportsvalid += 1
  53. print("Password Valid!")
  54. except:
  55. print("Field doesn't exist")
  56. continue
  57. print(passportsvalid)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement