diff --git a/examples/python/hidato.py b/examples/python/hidato.py index 7be074d206..cce234193a 100644 --- a/examples/python/hidato.py +++ b/examples/python/hidato.py @@ -41,7 +41,7 @@ Also see my other Google CP Solver models: http://www.hakank.org/google_or_tools/ """ - +from __future__ import print_function from ortools.constraint_solver import pywrapcp @@ -209,31 +209,31 @@ def main(): num_solutions = 0 while solver.NextSolution(): num_solutions += 1 - print "\nSolution:", num_solutions + print("\nSolution:", num_solutions) print_board(x, r, c) - print + print() solver.EndSearch() - print - print "num_solutions:", num_solutions - print "failures:", solver.Failures() - print "branches:", solver.Branches() - print "WallTime:", solver.WallTime() + print() + print("num_solutions:", num_solutions) + print("failures:", solver.Failures()) + print("branches:", solver.Branches()) + print("WallTime:", solver.WallTime()) def print_board(x, rows, cols): for i in range(rows): for j in range(cols): - print "% 2s" % x[i, j].Value(), - print "" + print("% 2s" % x[i, j].Value(), end=' ') + print("") def print_game(game, rows, cols): for i in range(rows): for j in range(cols): - print "% 2s" % game[i][j], - print "" + print("% 2s" % game[i][j], end=' ') + print("") if __name__ == "__main__": diff --git a/examples/python/hidato_table.py b/examples/python/hidato_table.py index c66e52369f..d4d4ea352f 100644 --- a/examples/python/hidato_table.py +++ b/examples/python/hidato_table.py @@ -23,7 +23,7 @@ diagonally. ''' """ - +from __future__ import print_function from ortools.constraint_solver import pywrapcp @@ -49,9 +49,9 @@ def BuildPairs(rows, cols): def main(): for model in range(1, 7): - print - print('----- Solving problem %i -----' % model) - print + print() + print(('----- Solving problem %i -----' % model)) + print() Solve(model) @@ -121,7 +121,7 @@ def Solve(model): r = len(puzzle) c = len(puzzle[0]) - print('Initial game (%i x %i)' % (r, c)) + print(('Initial game (%i x %i)' % (r, c))) PrintMatrix(puzzle) # @@ -166,15 +166,15 @@ def Solve(model): solver.EndSearch() - print('solutions : %i' % num_solutions) - print('failures : %i' % solver.Failures()) - print('branches : %i' % solver.Branches()) - print('wall time : %i' % solver.WallTime()) + print(('solutions : %i' % num_solutions)) + print(('failures : %i' % solver.Failures())) + print(('branches : %i' % solver.Branches())) + print(('wall time : %i' % solver.WallTime())) def PrintOneSolution(positions, rows, cols, num_solution): """Print a current solution.""" - print('Solution %i:' % num_solution) + print(('Solution %i:' % num_solution)) # Create empty board. board = [] for unused_i in range(rows): @@ -199,7 +199,7 @@ def PrintMatrix(game): else: line += '% 3s' % game[i][j] print(line) - print + print() if __name__ == '__main__': diff --git a/examples/python/integer_programming.py b/examples/python/integer_programming.py index 925521beac..c68708bbcc 100644 --- a/examples/python/integer_programming.py +++ b/examples/python/integer_programming.py @@ -56,8 +56,8 @@ def RunIntegerExampleCppStyleAPI(optimization_problem_type): def SolveAndPrint(solver, variable_list): """Solve the problem and print the solution.""" - print('Number of variables = %d' % solver.NumVariables()) - print('Number of constraints = %d' % solver.NumConstraints()) + print(('Number of variables = %d' % solver.NumVariables())) + print(('Number of constraints = %d' % solver.NumConstraints())) result_status = solver.Solve() @@ -68,22 +68,22 @@ def SolveAndPrint(solver, variable_list): # GLOP_LINEAR_PROGRAMMING, verifying the solution is highly recommended!). assert solver.VerifySolution(1e-7, True) - print('Problem solved in %f milliseconds' % solver.wall_time()) + print(('Problem solved in %f milliseconds' % solver.wall_time())) # The objective value of the solution. - print('Optimal objective value = %f' % solver.Objective().Value()) + print(('Optimal objective value = %f' % solver.Objective().Value())) # The value of each variable in the solution. for variable in variable_list: - print('%s = %f' % (variable.name(), variable.solution_value())) + print(('%s = %f' % (variable.name(), variable.solution_value()))) print('Advanced usage:') - print('Problem solved in %d branch-and-bound nodes' % solver.nodes()) + print(('Problem solved in %d branch-and-bound nodes' % solver.nodes())) def Announce(solver, api_type): - print ('---- Integer programming example with ' + solver + ' (' + - api_type + ') -----') + print(('---- Integer programming example with ' + solver + ' (' + + api_type + ') -----')) def RunAllIntegerExampleNaturalLanguageAPI(): diff --git a/examples/python/just_forgotten.py b/examples/python/just_forgotten.py index d708c7b2cd..8b97c500dc 100644 --- a/examples/python/just_forgotten.py +++ b/examples/python/just_forgotten.py @@ -45,7 +45,7 @@ Also see my other Google CP Solver models: http://www.hakank.org/google_or_tools/ """ - +from __future__ import print_function from ortools.constraint_solver import pywrapcp @@ -92,27 +92,27 @@ def main(): while solver.NextSolution(): num_solutions += 1 xval = [x[j].Value() for j in range(cols)] - print "Account number:" + print("Account number:") for j in range(cols): - print "%i " % xval[j], - print - print "\nThe four tries, where '!' represents a correct digit:" + print("%i " % xval[j], end=' ') + print() + print("\nThe four tries, where '!' represents a correct digit:") for i in range(rows): for j in range(cols): check = " " if a[i][j] == xval[j]: check = "!" - print "%i%s" % (a[i][j], check), - print - print - print + print("%i%s" % (a[i][j], check), end=' ') + print() + print() + print() solver.EndSearch() - print "num_solutions:", num_solutions - print "failures:", solver.Failures() - print "branches:", solver.Branches() - print "WallTime:", solver.WallTime() + print("num_solutions:", num_solutions) + print("failures:", solver.Failures()) + print("branches:", solver.Branches()) + print("WallTime:", solver.WallTime()) if __name__ == "__main__": main()