Skip to content

Commit 8443a07

Browse files
author
Philip Guo
committed
updated code examples to work on both Python 2 and 3
1 parent 5a0926b commit 8443a07

32 files changed

Lines changed: 55 additions & 55 deletions

v3/example-code/aliasing.golden

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"code": "x = [1, 2, 3]\ny = [4, 5, 6]\nz = y\ny = x\nx = z\n\nx = [1, 2, 3] # a different [1, 2, 3] list!\ny = x\nx.append(4)\ny.append(5)\nz = [1, 2, 3, 4, 5] # a different list!\nx.append(6)\ny.append(7)\ny = \"hello\"\n\n\ndef foo(lst):\n lst.append(\"hello\")\n bar(lst)\n\ndef bar(myLst):\n print myLst\n\nfoo(x)\nfoo(z)\n",
2+
"code": "x = [1, 2, 3]\ny = [4, 5, 6]\nz = y\ny = x\nx = z\n\nx = [1, 2, 3] # a different [1, 2, 3] list!\ny = x\nx.append(4)\ny.append(5)\nz = [1, 2, 3, 4, 5] # a different list!\nx.append(6)\ny.append(7)\ny = \"hello\"\n\n\ndef foo(lst):\n lst.append(\"hello\")\n bar(lst)\n\ndef bar(myLst):\n print(myLst)\n\nfoo(x)\nfoo(z)\n",
33
"trace": [
44
{
55
"ordered_globals": [],

v3/example-code/aliasing.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def foo(lst):
1919
bar(lst)
2020

2121
def bar(myLst):
22-
print myLst
22+
print(myLst)
2323

2424
foo(x)
2525
foo(z)

v3/example-code/closures/lambda-param.golden

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"code": "def foo(x):\n bar(lambda y: x + y)\n\ndef bar(a):\n print a(20)\n\nfoo(10)\n",
2+
"code": "def foo(x):\n bar(lambda y: x + y)\n\ndef bar(a):\n print(a(20))\n\nfoo(10)\n",
33
"trace": [
44
{
55
"ordered_globals": [],

v3/example-code/closures/lambda-param.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,6 @@ def foo(x):
22
bar(lambda y: x + y)
33

44
def bar(a):
5-
print a(20)
5+
print(a(20))
66

77
foo(10)

v3/example-code/fact.golden

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"code": "# dumb recursive factorial\ndef fact(n):\n if (n <= 1):\n return 1\n else:\n return n * fact(n - 1)\n\nprint fact(6)\n",
2+
"code": "# dumb recursive factorial\ndef fact(n):\n if (n <= 1):\n return 1\n else:\n return n * fact(n - 1)\n\nprint(fact(6))\n",
33
"trace": [
44
{
55
"ordered_globals": [],

v3/example-code/fact.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@ def fact(n):
55
else:
66
return n * fact(n - 1)
77

8-
print fact(6)
8+
print(fact(6))

v3/example-code/fib.golden

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"code": "# Infinite Fibonacci!!!\n\narr = [1, 1]\n\nprint arr[0]\n\nwhile True:\n print arr[-1]\n tmp = sum(arr)\n arr.append(tmp)\n del arr[0]\n",
2+
"code": "# Infinite Fibonacci!!!\n\narr = [1, 1]\n\nprint(arr[0])\n\nwhile True:\n print(arr[-1])\n tmp = sum(arr)\n arr.append(tmp)\n del arr[0]\n",
33
"trace": [
44
{
55
"ordered_globals": [],

v3/example-code/fib.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22

33
arr = [1, 1]
44

5-
print arr[0]
5+
print(arr[0])
66

77
while True:
8-
print arr[-1]
8+
print(arr[-1])
99
tmp = sum(arr)
1010
arr.append(tmp)
1111
del arr[0]

v3/example-code/filter.golden

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
{
2-
"code": "input = [(\"Mary\", 27), (\"Joe\", 30), (\"Ruth\", 43), (\"Bob\", 17), (\"Jenny\", 22)]\n\nyoungPeople = []\n\nfor (person, age) in input:\n if age < 30:\n youngPeople.append(person)\n else:\n print \"HAHA\", person, \"is too old!\"\n\nprint \"There are\", len(youngPeople), \"young people\"\n",
2+
"code": "input = [(\"Mary\", 27), (\"Joe\", 30), (\"Ruth\", 43), (\"Bob\", 17), (\"Jenny\", 22)]\n\nyoungPeople = []\n\nfor (person, age) in input:\n if age < 30:\n youngPeople.append(person)\n else:\n print(\"HAHA \" + person + \" is too old!\")\n\nprint(\"There are \" + str(len(youngPeople)) + \" young people\")\n",
33
"trace": [
44
{
55
"ordered_globals": [],

v3/example-code/filter.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@ for (person, age) in input:
66
if age < 30:
77
youngPeople.append(person)
88
else:
9-
print "HAHA", person, "is too old!"
9+
print("HAHA " + person + " is too old!")
1010

11-
print "There are", len(youngPeople), "young people"
11+
print("There are " + str(len(youngPeople)) + " young people")

0 commit comments

Comments
 (0)