Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- passports = open("material.txt", "r").read().split("\n\n")
- passportsvalid = 0
- for passport in passports:
- passwordvalid = True
- passport = passport.replace('\n', ' ')
- fieldlist = passport.split(' ')
- d = dict(f.split(":") for f in fieldlist)
- try:
- if(not 1920 <= int(d['byr']) <= 2002):
- passwordvalid = False
- continue
- if(not 2010 <= int(d['iyr']) <= 2020):
- passwordvalid = False
- continue
- if(not 2020 <= int(d['eyr']) <= 2030):
- passwordvalid = False
- continue
- if("cm" in d['hgt']):
- if(not 150 <= int(d['hgt'][:len(d['hgt'])-2]) <= 193):
- passwordvalid = False
- continue
- elif("in" in d['hgt']):
- if(not 59 <= int(d['hgt'][:len(d['hgt'])-2]) <= 76):
- passwordvalid = False
- continue
- if(not d['hcl'][0] == "#"):
- passwordvalid = False
- continue
- else:
- if(len(d['hcl'][1:]) == 6):
- try:
- isint = int(d['hcl'][1:],16)
- except:
- passwordvalid = False
- continue
- else:
- passwordvalid = False
- continue
- if(not d['ecl'] in "amb blu brn gry grn hzl oth".split()):
- passwordvalid = False
- continue
- if(not len(d['pid']) == 9):
- passwordvalid = False
- continue
- else:
- try:
- isint = int(d['pid'])
- except:
- passwordvalid = False
- continue
- passportsvalid += 1
- print("Password Valid!")
- except:
- print("Field doesn't exist")
- continue
- print(passportsvalid)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement