File tree

1 file changed

+7
-5
lines changed

1 file changed

+7
-5
lines changed
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
5. assume it can be more restrictive but one can have a extra check where the
2424
postal code is always 6 digits long as it is always for Banglore location.
2525
26-
26+
6. Final assumption is that assertions will always be turned on while using also
2727
########################################################################
2828
approach to the problem
2929
@@ -65,8 +65,8 @@ def write_outfile(ranks, outputfile_name="topthree.txt"):
6565
'No of Parcels Delivered', '\n'))
6666
for pin_code, no_delivery in ranks:
6767
count += 1
68-
opfile.write(template.format(str(count)+".", pin_code, str(count),
69-
str(no_delivery), '\n'))
68+
opfile.write(template.format(str(count) + ".",
69+
pin_code, str(count), str(no_delivery), '\n'))
7070
except IOError:
7171
return "IO failed"
7272
except AssertionError:
@@ -90,12 +90,15 @@ def ranksetter(ranklist, no_delivery, postalcode):
9090
ranksetter([('456098', 3), ('567789', 2), ('560089', 1)], 5, "234561")
9191
"""
9292
try:
93+
#input type assertion checks
9394
assert(isinstance(ranklist, list))
9495
assert(isinstance(no_delivery, int))
9596
assert(isinstance(postalcode, str))
9697
assert(postalcode.isdigit())
98+
#allowd length checks
9799
assert(len(ranklist) == 3)
98100
assert(len(postalcode) == 6)
101+
#delivery must be non negative and integral
99102
assert(no_delivery >= 0)
100103
check_list = [val[1] for val in ranklist]
101104
exp_list = check_list[:]
@@ -147,7 +150,7 @@ def matcher_and_extractor(constraint_string, input_sub_string,
147150
assert(input_sub_string[constraint_length].isdigit())
148151
# is the postal code what we think is digits only and note always we
149152
#consider it only 6 digit length
150-
postal_code = input_sub_string[constraint_length: constraint_length+6]
153+
postal_code = input_sub_string[constraint_length: constraint_length + 6]
151154
assert(postal_code.isdigit())
152155
return postal_code
153156
except AssertionError:
@@ -187,7 +190,6 @@ def toppostalcodes(input_filename):
187190
for p_code in postalcodedict:
188191
ranker = ranksetter(ranker, postalcodedict[p_code], p_code)
189192
assert(ranker is not None)
190-
print ranker
191193
return write_outfile(ranker)
192194
except AssertionError:
193195
return

0 commit comments

Comments
 (0)