diff --git a/examples/python/fill_a_pix.py b/examples/python/fill_a_pix.py index 7b84aabfb0..69de05360a 100644 --- a/examples/python/fill_a_pix.py +++ b/examples/python/fill_a_pix.py @@ -51,6 +51,7 @@ Also see my other Google CP Solver models: http://www.hakank.org/google_or_tools/ """ +from __future__ import print_function import sys from ortools.constraint_solver import pywrapcp @@ -87,21 +88,21 @@ def main(puzzle='', n=''): puzzle = default_puzzle n = default_n else: - print 'n:', n + print('n:', n) # for the neighbors of 'this' cell S = [-1, 0, 1] # print problem instance - print 'Problem:' + print('Problem:') for i in range(n): for j in range(n): if puzzle[i][j] == X: sys.stdout.write('.') else: sys.stdout.write(str(puzzle[i][j])) - print - print + print() + print() # # declare variables @@ -138,7 +139,7 @@ def main(puzzle='', n=''): solver.NewSearch(db) num_solutions = 0 - print 'Solution:' + print('Solution:') while solver.NextSolution(): num_solutions += 1 for i in range(n): @@ -148,13 +149,13 @@ def main(puzzle='', n=''): row[j] = ' ' else: row[j] = '#' - print ''.join(row) - print + print(''.join(row)) + print() - print 'num_solutions:', num_solutions - print 'failures:', solver.Failures() - print 'branches:', solver.Branches() - print 'WallTime:', solver.WallTime(), 'ms' + print('num_solutions:', num_solutions) + print('failures:', solver.Failures()) + print('branches:', solver.Branches()) + print('WallTime:', solver.WallTime(), 'ms') # @@ -180,7 +181,7 @@ def read_problem(file): if __name__ == '__main__': if len(sys.argv) > 1: file = sys.argv[1] - print 'Problem instance from', file + print('Problem instance from', file) [puzzle, n] = read_problem(file) main(puzzle, n) else: diff --git a/examples/python/furniture_moving.py b/examples/python/furniture_moving.py index 12bd8f2b5e..03ce1cd95a 100644 --- a/examples/python/furniture_moving.py +++ b/examples/python/furniture_moving.py @@ -36,7 +36,7 @@ Also see my other Google CP Solver models: http://www.hakank.org/google_or_tools/ """ - +from __future__ import print_function import sys from ortools.constraint_solver import pywrapcp @@ -67,7 +67,7 @@ def my_cumulative(solver, s, d, r, b): tasks = [i for i in range(len(s)) if r[i] > 0 and d[i] > 0] times_min = min([s[i].Min() for i in tasks]) times_max = max([s[i].Max() + max(d) for i in tasks]) - for t in xrange(times_min, times_max + 1): + for t in range(times_min, times_max + 1): bb = [] for i in tasks: c1 = solver.IsLessOrEqualCstVar(s[i], t) # s[i] <= t @@ -156,20 +156,20 @@ def main(): num_solutions = 0 while solver.NextSolution(): num_solutions += 1 - print "num_resources:", num_resources.Value() - print "start_times :", [start_times[i].Value() for i in range(n)] - print "duration :", [duration[i] for i in range(n)] - print "end_times :", [end_times[i].Value() for i in range(n)] - print "end_time :", end_time.Value() - print + print("num_resources:", num_resources.Value()) + print("start_times :", [start_times[i].Value() for i in range(n)]) + print("duration :", [duration[i] for i in range(n)]) + print("end_times :", [end_times[i].Value() for i in range(n)]) + print("end_time :", end_time.Value()) + 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()) if __name__ == "__main__": main() diff --git a/examples/python/futoshiki.py b/examples/python/futoshiki.py index c61b25ede5..f8100d3826 100644 --- a/examples/python/futoshiki.py +++ b/examples/python/futoshiki.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 @@ -58,8 +58,8 @@ def main(values, lt): # data # size = len(values) - RANGE = range(size) - NUMQD = range(len(lt)) + RANGE = list(range(size)) + NUMQD = list(range(len(lt))) # # variables @@ -107,16 +107,16 @@ def main(values, lt): num_solutions += 1 for i in RANGE: for j in RANGE: - print field[i, j].Value(), - print - print + print(field[i, j].Value(), end=' ') + 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()) # @@ -183,7 +183,7 @@ lt2 = [ if __name__ == "__main__": - print "Problem 1" + print("Problem 1") main(values1, lt1) - print "\nProblem 2" + print("\nProblem 2") main(values2, lt2)