Skip to content

Commit f6ca5cb

Browse files
author
Charlotte Weaver
committed
python 3 compliant
1 parent 899c7f8 commit f6ca5cb

File tree

2 files changed

+28
-29
lines changed

2 files changed

+28
-29
lines changed
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
birth_year = raw_input("What is the birth year for the milestones?")
1+
birth_year = input("What is the birth year for the milestones?")
22
# raw_input always gives strings, so convert to int
33
birth_year = int(birth_year)
44

@@ -7,6 +7,6 @@
77
drinking_year = birth_year + 21
88
president_year = birth_year + 35
99

10-
print "You are able to drive in " + str(driving_year)
11-
print "You are able to drink in " + str(drinking_year)
12-
print "You are able to run for president in " + str(president_year)
10+
print("You are able to drive in " + str(driving_year))
11+
print("You are able to drink in " + str(drinking_year))
12+
print("You are able to run for president in " + str(president_year))

Lesson01_Variables/lesson01.ipynb

Lines changed: 24 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -57,9 +57,9 @@
5757
"cell_type": "markdown",
5858
"metadata": {},
5959
"source": [
60-
"To print a value to the screen, we use the command 'print'\n",
60+
"To print a value to the screen, we use the function 'print()'\n",
6161
"\n",
62-
"e.g. print 1"
62+
"e.g. print(1)"
6363
]
6464
},
6565
{
@@ -70,7 +70,7 @@
7070
},
7171
"outputs": [],
7272
"source": [
73-
"print \"Hello World\""
73+
"print(\"Hello World\")"
7474
]
7575
},
7676
{
@@ -122,7 +122,7 @@
122122
"cell_type": "markdown",
123123
"metadata": {},
124124
"source": [
125-
"Notice that when you ran that, nothing printed out. To print a variable, you use the same statement you would use to print the value. e.g. print WHALE"
125+
"Notice that when you ran that, nothing printed out. To print a variable, you use the same statement you would use to print the value. e.g. print(WHALE)"
126126
]
127127
},
128128
{
@@ -133,7 +133,7 @@
133133
},
134134
"outputs": [],
135135
"source": [
136-
"print number_of_whales"
136+
"print(number_of_whales)"
137137
]
138138
},
139139
{
@@ -201,7 +201,7 @@
201201
"source": [
202202
"apples = 15\n",
203203
"apples_left = 15 - 3\n",
204-
"print apples_left"
204+
"print(apples_left)"
205205
]
206206
},
207207
{
@@ -212,7 +212,7 @@
212212
},
213213
"outputs": [],
214214
"source": [
215-
"print 3 * 2.1"
215+
"print(3 * 2.1)"
216216
]
217217
},
218218
{
@@ -234,7 +234,7 @@
234234
},
235235
"outputs": [],
236236
"source": [
237-
"print 5 / 2"
237+
"print(5 / 2)"
238238
]
239239
},
240240
{
@@ -274,7 +274,7 @@
274274
"source": [
275275
"number_of_whales = 8\n",
276276
"number_of_whales = number_of_whales + 2 \n",
277-
"print number_of_whales"
277+
"print(number_of_whales)"
278278
]
279279
},
280280
{
@@ -378,7 +378,7 @@
378378
},
379379
"outputs": [],
380380
"source": [
381-
"print 'Hello ' + 'Coding Circle'"
381+
"print('Hello ' + 'Coding Circle')"
382382
]
383383
},
384384
{
@@ -389,7 +389,7 @@
389389
},
390390
"outputs": [],
391391
"source": [
392-
"print \"The \" + WHALE + \" lives in the sea.\""
392+
"print(\"The \" + WHALE + \" lives in the sea.\")"
393393
]
394394
},
395395
{
@@ -407,7 +407,7 @@
407407
},
408408
"outputs": [],
409409
"source": [
410-
"print \"My name is\" + \"Charlotte\""
410+
"print(\"My name is\" + \"Charlotte\")"
411411
]
412412
},
413413
{
@@ -446,8 +446,8 @@
446446
},
447447
"outputs": [],
448448
"source": [
449-
"my_name = raw_input()\n",
450-
"print my_name"
449+
"my_name = input()\n",
450+
"print(my_name)"
451451
]
452452
},
453453
{
@@ -469,8 +469,8 @@
469469
},
470470
"outputs": [],
471471
"source": [
472-
"favorite_ocean_animal = raw_input(\"What is your favorite sea creature?\\n\")\n",
473-
"print \"The \" + favorite_ocean_animal + \" is so cool!\""
472+
"favorite_ocean_animal = input(\"What is your favorite sea creature?\\n\")\n",
473+
"print(\"The \" + favorite_ocean_animal + \" is so cool!\")"
474474
]
475475
},
476476
{
@@ -492,9 +492,9 @@
492492
},
493493
"outputs": [],
494494
"source": [
495-
"number_of_apples = raw_input(\"How many apples do you want?\\n\")\n",
495+
"number_of_apples = input(\"How many apples do you want?\\n\")\n",
496496
"number_of_apples_int = int(number_of_apples)\n",
497-
"print int(number_of_apples_int) * 1.05"
497+
"print(int(number_of_apples_int) * 1.05)"
498498
]
499499
},
500500
{
@@ -533,9 +533,9 @@
533533
"outputs": [],
534534
"source": [
535535
"# Calculate the price of apples that a user wants\n",
536-
"number_of_apples = raw_input(\"How many apples do you want?\\n\") # Ask user for quantity of apples\n",
536+
"number_of_apples = input(\"How many apples do you want?\\n\") # Ask user for quantity of apples\n",
537537
"number_of_apples_int = int(number_of_apples) # raw_input returns string, so convert to integer\n",
538-
"print number_of_apples_int * 1.05 # multiply by price of apples"
538+
"print(number_of_apples_int * 1.05) # multiply by price of apples"
539539
]
540540
},
541541
{
@@ -585,21 +585,20 @@
585585
],
586586
"metadata": {
587587
"kernelspec": {
588-
"display_name": "Python 2",
588+
"display_name": "Python 3",
589589
"language": "python",
590-
"name": "python2"
590+
"name": "python3"
591591
},
592592
"language_info": {
593593
"codemirror_mode": {
594594
"name": "ipython",
595-
"version": 2
595+
"version": 3
596596
},
597597
"file_extension": ".py",
598598
"mimetype": "text/x-python",
599599
"name": "python",
600600
"nbconvert_exporter": "python",
601-
"pygments_lexer": "ipython2",
602-
"version": "2.7.10"
601+
"pygments_lexer": "ipython3"
603602
}
604603
},
605604
"nbformat": 4,

0 commit comments

Comments
 (0)