From 2378525af91ece62acc41cd5f2fa47129da3fc5c Mon Sep 17 00:00:00 2001 From: Andres Lowrie Date: Fri, 20 Nov 2020 11:28:16 -0600 Subject: [PATCH] fix: make factorial script work with python3 In particular I used: `Python 3.8.6` --- book/2e/02.Rmd | 4 ++-- book/2e/data/ch02/fac.py | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/book/2e/02.Rmd b/book/2e/02.Rmd index f8882a1c..e52d54c3 100644 --- a/book/2e/02.Rmd +++ b/book/2e/02.Rmd @@ -196,14 +196,14 @@ Interpreted Script def factorial(x): result = 1 - for i in xrange(2, x + 1): + for i in range(2, x + 1): result *= i return result if __name__ == "__main__": import sys x = int(sys.argv[1]) - print factorial(x) + print(factorial(x)) ``` This script computes the factorial of the integer that we pass as a parameter. It can be invoked from the command line as follows: diff --git a/book/2e/data/ch02/fac.py b/book/2e/data/ch02/fac.py index c88d60c4..6fbf7767 100755 --- a/book/2e/data/ch02/fac.py +++ b/book/2e/data/ch02/fac.py @@ -2,11 +2,11 @@ def factorial(x): result = 1 - for i in xrange(2, x + 1): + for i in range(2, x + 1): result *= i return result if __name__ == "__main__": import sys x = int(sys.argv[1]) - print factorial(x) + print(factorial(x))