Nov-19-2019, 06:42 AM
(Nov-17-2019, 12:36 AM)Than999 Wrote: So the "verify" function is suppose to verify and "pass" or "fail" any given string list in the format of '####-####-####', based on four rules.
So the function should return 'pass' or 'fail' for give string, not the compliance to specific rule?
>>> def verify(string): ... digits = ''.join(char for char in string if char.isdigit()) ... first_rule = digits[0] == '4' ... second_rule = int(digits[3]) - int(digits[4]) == 1 ... third_rule = sum(int(num) for num in digits) % 4 == 0 ... fourth_rule = int(digits[:2]) + int(digits[6:8]) == 100 ... if all([first_rule, second_rule, third_rule, fourth_rule]): ... return 'pass' ... else: ... return 'fail' ... >>> verify('4094-3460-2754') 'pass' >>> verify('4084-3460-2754') 'fail'
I'm not 'in'-sane. Indeed, I am so far 'out' of sane that you appear a tiny blip on the distant coast of sanity. Bucky Katt, Get Fuzzy
Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.
Da Bishop: There's a dead bishop on the landing. I don't know who keeps bringing them in here. ....but society is to blame.