From 1571e499c67254301bba0408940150eccfc15052 Mon Sep 17 00:00:00 2001 From: Nishant Suman Date: Sun, 6 Mar 2016 23:58:10 +0530 Subject: [PATCH 1/2] print in csp.py is now used as function All print statement in csp.py is now converted into print function --- csp.py | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/csp.py b/csp.py index 1ec2f63b8..171e4080d 100644 --- a/csp.py +++ b/csp.py @@ -460,13 +460,13 @@ def display(self, assignment): if assignment.get(var,'') == val: ch = 'Q' elif (var+val) % 2 == 0: ch = '.' else: ch = '-' - print ch, + print (ch), print ' ', for var in range(n): if assignment.get(var,'') == val: ch = '*' else: ch = ' ' - print str(self.nconflicts(var, val, assignment))+ch, - print + print ((str(self.nconflicts(var, val, assignment))+ch),) + print () #______________________________________________________________________________ # Sudoku @@ -541,8 +541,8 @@ def display(self, assignment): def show_box(box): return [' '.join(map(show_cell, row)) for row in box] def show_cell(cell): return str(assignment.get(cell, '.')) def abut(lines1, lines2): return map(' | '.join, zip(lines1, lines2)) - print '\n------+-------+------\n'.join( - '\n'.join(reduce(abut, map(show_box, brow))) for brow in self.bgrid) + print ('\n------+-------+------\n'.join( + '\n'.join(reduce(abut, map(show_box, brow))) for brow in self.bgrid)) #______________________________________________________________________________ # The Zebra Puzzle @@ -599,10 +599,10 @@ def solve_zebra(algorithm=min_conflicts, **args): z = Zebra() ans = algorithm(z, **args) for h in range(1, 6): - print 'House', h, + print ('House', h,) for (var, val) in ans.items(): if val == h: print var, - print + print () return ans['Zebra'], ans['Water'], z.nassigns, ans From c61cb2a495fe290182895e572fcfd6c88fe0aa04 Mon Sep 17 00:00:00 2001 From: Nishant Suman Date: Mon, 7 Mar 2016 00:02:49 +0530 Subject: [PATCH 2/2] Updated csp.py with print function --- csp.py | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/csp.py b/csp.py index 171e4080d..3d36a6d0f 100644 --- a/csp.py +++ b/csp.py @@ -73,7 +73,7 @@ def conflict(var2): def display(self, assignment): "Show a human-readable representation of the CSP." # Subclasses can print in a prettier way, or display with a GUI - print 'CSP:', self, 'with assignment:', assignment + print ('CSP:', self, 'with assignment:', assignment) ## These methods are for the tree- and graph-search interface: @@ -461,7 +461,7 @@ def display(self, assignment): elif (var+val) % 2 == 0: ch = '.' else: ch = '-' print (ch), - print ' ', + print (' ',) for var in range(n): if assignment.get(var,'') == val: ch = '*' else: ch = ' ' @@ -601,7 +601,7 @@ def solve_zebra(algorithm=min_conflicts, **args): for h in range(1, 6): print ('House', h,) for (var, val) in ans.items(): - if val == h: print var, + if val == h: print (var,) print () return ans['Zebra'], ans['Water'], z.nassigns, ans