Skip to content

Commit f4d9af1

Browse files
author
Charlotte Weaver
committed
update lesson2 to python3
1 parent 87bd23c commit f4d9af1

File tree

2 files changed

+45
-45
lines changed

2 files changed

+45
-45
lines changed
Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
11
# Ask get budget for car from user
2-
budget = raw_input("What is your budget for a car?\n")
2+
budget = input("What is your budget for a car?\n")
33
try:
4-
# raw_input returns a string and we need a number so convert to int
4+
# input returns a string and we need a number so convert to int
55
budget = int(budget)
66
if (budget > 75000):
7-
print "You should buy a Tesla!"
7+
print("You should buy a Tesla!")
88
elif (budget < 500):
9-
print "You are probably better off taking the bus..."
9+
print("You are probably better off taking the bus...")
1010
else:
11-
print "I don't know, maybe a Toyota Corolla?"
11+
print("I don't know, maybe a Toyota Corolla?")
1212
# This will execute if the budget can't be converted to an int
1313
except:
14-
print "Please be realistic, you can't buy a car on rainbows and love"
14+
print("Please be realistic, you can't buy a car on rainbows and love")
1515
# This will execute no matter what
16-
print "You can get all your shopping done at Charlotte's Auto Depot!"
16+
print("You can get all your shopping done at Charlotte's Auto Depot!")

Lesson02_Conditionals/Conditional Execution.ipynb

Lines changed: 38 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@
2121
"cleaned_room = True\n",
2222
"took_out_trash = False\n",
2323
"\n",
24-
"print cleaned_room\n",
25-
"print type(took_out_trash)"
24+
"print(cleaned_room)\n",
25+
"print(type(took_out_trash))"
2626
]
2727
},
2828
{
@@ -60,7 +60,7 @@
6060
},
6161
"outputs": [],
6262
"source": [
63-
"print 5 == 6"
63+
"print(5 == 6)"
6464
]
6565
},
6666
{
@@ -71,7 +71,7 @@
7171
},
7272
"outputs": [],
7373
"source": [
74-
"print \"Hello\" != \"Goodbye\""
74+
"print(\"Hello\" != \"Goodbye\")"
7575
]
7676
},
7777
{
@@ -85,7 +85,7 @@
8585
"# You can compare to variables too\n",
8686
"x = 5\n",
8787
"\n",
88-
"print 5 >= x"
88+
"print(5 >= x)"
8989
]
9090
},
9191
{
@@ -96,7 +96,7 @@
9696
},
9797
"outputs": [],
9898
"source": [
99-
"print x is True"
99+
"print(x is True)"
100100
]
101101
},
102102
{
@@ -142,13 +142,13 @@
142142
"source": [
143143
"# cleaned_room is true\n",
144144
"if cleaned_room:\n",
145-
" print \"Good girl! You can watch TV.\"\n",
145+
" print(\"Good girl! You can watch TV.\")\n",
146146
" \n",
147147
"# took_out_trash if false\n",
148148
"if took_out_trash:\n",
149-
" print \"Thank you!\"\n",
149+
" print(\"Thank you!\")\n",
150150
" \n",
151-
"print took_out_trash"
151+
"print(took_out_trash)"
152152
]
153153
},
154154
{
@@ -180,8 +180,8 @@
180180
"source": [
181181
"# cleaned_room is true\n",
182182
"if cleaned_room:\n",
183-
" print \"Good job! You can watch TV.\"\n",
184-
" print \"Or play outside\""
183+
" print(\"Good job! You can watch TV.\")\n",
184+
" print(\"Or play outside\")"
185185
]
186186
},
187187
{
@@ -194,9 +194,9 @@
194194
"source": [
195195
"# took_out_trash is false\n",
196196
"if took_out_trash:\n",
197-
" print \"Thank you!\"\n",
198-
" print \"You are a good helper\"\n",
199-
"print \"It is time for lunch\""
197+
" print(\"Thank you!\")\n",
198+
" print(\"You are a good helper\")\n",
199+
"print(\"It is time for lunch\")"
200200
]
201201
},
202202
{
@@ -226,9 +226,9 @@
226226
"candies_taken = 4\n",
227227
"\n",
228228
"if (candies_taken < 3):\n",
229-
" print 'Enjoy!'\n",
229+
" print('Enjoy!')\n",
230230
"else:\n",
231-
" print 'Put some back'"
231+
" print('Put some back')"
232232
]
233233
},
234234
{
@@ -278,7 +278,7 @@
278278
" allowance = 4\n",
279279
"else:\n",
280280
" allowance = 2\n",
281-
"print allowance"
281+
"print(allowance)"
282282
]
283283
},
284284
{
@@ -339,11 +339,11 @@
339339
},
340340
"outputs": [],
341341
"source": [
342-
"print True and True\n",
342+
"print(True and True)\n",
343343
"\n",
344-
"print False or True\n",
344+
"print(False or True)\n",
345345
"\n",
346-
"print not False"
346+
"print(not False)"
347347
]
348348
},
349349
{
@@ -364,9 +364,9 @@
364364
"cleaned_room = True\n",
365365
"took_out_trash = False\n",
366366
"if (cleaned_room and took_out_trash):\n",
367-
" print \"Let's go to Chuck-E-Cheese's.\"\n",
367+
" print(\"Let's go to Chuck-E-Cheese's.\")\n",
368368
"else:\n",
369-
" print \"Get to work!\""
369+
" print(\"Get to work!\")"
370370
]
371371
},
372372
{
@@ -378,7 +378,7 @@
378378
"outputs": [],
379379
"source": [
380380
"if (not did_homework):\n",
381-
" print \"You're going to get a bad grade.\""
381+
" print(\"You're going to get a bad grade.\")"
382382
]
383383
},
384384
{
@@ -428,11 +428,11 @@
428428
"\n",
429429
"if (allowance > 2):\n",
430430
" if (allowance >= 8):\n",
431-
" print \"Buy toys!\"\n",
431+
" print(\"Buy toys!\")\n",
432432
" else:\n",
433-
" print \"Buy candy!\"\n",
433+
" print(\"Buy candy!\")\n",
434434
"else:\n",
435-
" print \"Save it until I have enough to buy something good.\""
435+
" print(\"Save it until I have enough to buy something good.\")"
436436
]
437437
},
438438
{
@@ -458,11 +458,11 @@
458458
"outputs": [],
459459
"source": [
460460
"try:\n",
461-
" print \"Before\"\n",
461+
" print(\"Before\")\n",
462462
" y = 5/0\n",
463-
" print \"After\"\n",
463+
" print(\"After\")\n",
464464
"except:\n",
465-
" print \"I'm sorry, the universe doesn't work that way...\""
465+
" print(\"I'm sorry, the universe doesn't work that way...\")"
466466
]
467467
},
468468
{
@@ -480,13 +480,13 @@
480480
},
481481
"outputs": [],
482482
"source": [
483-
"inp = raw_input('Enter Fahrenheit Temperature:')\n",
483+
"inp = input('Enter Fahrenheit Temperature:')\n",
484484
"try:\n",
485485
" fahr = float(inp)\n",
486486
" cel = (fahr - 32.0) * 5.0 / 9.0\n",
487-
" print cel\n",
487+
" print(cel)\n",
488488
"except:\n",
489-
" print 'Please enter a number'"
489+
" print('Please enter a number')"
490490
]
491491
},
492492
{
@@ -528,7 +528,7 @@
528528
"outputs": [],
529529
"source": [
530530
"if ((1 < 2) or (5/0)):\n",
531-
" print \"How did we do that?\""
531+
" print(\"How did we do that?\")"
532532
]
533533
},
534534
{
@@ -560,21 +560,21 @@
560560
],
561561
"metadata": {
562562
"kernelspec": {
563-
"display_name": "Python 2",
563+
"display_name": "Python 3",
564564
"language": "python",
565-
"name": "python2"
565+
"name": "python3"
566566
},
567567
"language_info": {
568568
"codemirror_mode": {
569569
"name": "ipython",
570-
"version": 2
570+
"version": 3
571571
},
572572
"file_extension": ".py",
573573
"mimetype": "text/x-python",
574574
"name": "python",
575575
"nbconvert_exporter": "python",
576-
"pygments_lexer": "ipython2",
577-
"version": "2.7.10"
576+
"pygments_lexer": "ipython3",
577+
"version": "3.5.2"
578578
}
579579
},
580580
"nbformat": 4,

0 commit comments

Comments
 (0)