Skip to content

Commit a0f8f66

Browse files
author
Charlotte Weaver
committed
Minor formatting updates
1 parent 6e861d2 commit a0f8f66

1 file changed

Lines changed: 15 additions & 11 deletions

File tree

Lesson04_Iteration/Iterations.ipynb

Lines changed: 15 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@
5656
},
5757
"outputs": [],
5858
"source": [
59-
"# print count\n",
60-
"# count += 5\n",
59+
"print count\n",
60+
"count += 5\n",
6161
"print count\n",
6262
"count *= 2\n",
6363
"print count"
@@ -133,7 +133,8 @@
133133
"source": [
134134
"## Infinite loops\n",
135135
"One thing you need to be careful of with while loops is the case where the condition never turns false. This means that the loop will keep going and going forever. You'll hear your computer's fan heat up and the program will hang. If you are doing any significant amount of programming, you will write an infinite loop, it cannot be helped. But watch out for them anyways.\n",
136-
"\n"
136+
"\n",
137+
"**HINT** To stop an infinite loop in a jupyter notebook select Kernel->Restart from the menu above.\n"
137138
]
138139
},
139140
{
@@ -288,6 +289,7 @@
288289
"source": [
289290
"while True:\n",
290291
" user_message = raw_input('> ')\n",
292+
" # Leave when the user talks about snow.\n",
291293
" if user_message == 'snow':\n",
292294
" print \"I don't want to hear about that.\"\n",
293295
" break\n",
@@ -307,6 +309,7 @@
307309
"while index < len(stock_up):\n",
308310
" item = stock_up[index]\n",
309311
" index += 1\n",
312+
" # Make sure we don't stock up on puppies\n",
310313
" if item == 'puppies':\n",
311314
" print \"No! We are not getting another puppy\"\n",
312315
" continue\n",
@@ -434,13 +437,14 @@
434437
},
435438
{
436439
"cell_type": "code",
437-
"execution_count": 1,
440+
"execution_count": null,
438441
"metadata": {
439442
"collapsed": false
440443
},
441444
"outputs": [],
442445
"source": [
443-
"words = ['Oh', 'the', 'weather', 'outside', 'is', 'frightful', 'But', 'the', 'fire', 'is', 'so', 'delightful']"
446+
"words = ['Oh', 'the', 'weather', 'outside', 'is', 'frightful', 'But', 'the', 'fire', 'is', 'so', 'delightful']\n",
447+
"# Your code goes here\n"
444448
]
445449
},
446450
{
@@ -458,23 +462,23 @@
458462
"\n",
459463
"We are going to create a program that lets a user move N, S, E, or W and keeps track of their location. In phase two, we will introduce a treasure and let the user know if they found it.\n",
460464
"## Phase 1: wandering\n",
461-
"1. Initialize two variables wanderer_x and wanderer_y to 0.\n",
465+
"1. Initialize two variables `wanderer_x` and `wanderer_y` to 0.\n",
462466
"2. In an infinate while loop:\n",
463-
" - prompt the user \"Which direction would you like to travel in? (N, S, E, or W. done to quit)\" and store in a variable called direction\n",
464-
" - Update the user's location depending on their choice: add 1 to wanderer_x if E, subtract 1 from wanderer_x if W, add 1 to wanderer_y if N, subtract 1 from wanderer_y if S.\n",
467+
" - prompt the user \"Which direction would you like to travel in? (N, S, E, or W. done to quit)\" and store in a variable called `direction`\n",
468+
" - Update the user's location depending on their choice: add 1 to `wanderer_x` if E, subtract 1 from `wanderer_x` if W, add 1 to `wanderer_y` if N, subtract 1 from `wanderer_y` if S.\n",
465469
" - If their response is 'done' break out of the loop.\n",
466470
"3. Tell the user their location \n",
467471
"\n",
468472
"## Phase 2: treasure\n",
469-
"1. Initialize treasure_x and treasure_y to integers of your choice (don't make them too big or you'll have to spend too long to treasure hunt). Include this after you initialize the wanderer's location.\n",
473+
"1. Initialize `treasure_x` and `treasure_y` to integers of your choice (don't make them too big or you'll have to spend too long to treasure hunt). Include this after you initialize the wanderer's location.\n",
470474
"2. In the while loop, after the user's location has been updated, if they are in the same location as the treasure, congratulate them and break out of the loop.\n",
471475
"\n",
472476
"## Phase 3: this was too easy\n",
473477
"Here are some ideas for how to improve your program.\n",
474478
"1. Make the location of the treasure random. ( x and y between -10 and 10)\n",
475479
"2. Set a time limit to find the treasure. Instead of an infinite loop, use a for loop from 0 - 50.\n",
476480
"3. Tell the user how far they walked d = sqrt( (x2 - x1)^2 + (y2 - y1)^2) **Hint** check the math module\n",
477-
"4. You should probably make number 3 a function called distance that takes four parameters (x1, x2, y1, y2) and returns the distance.\n",
481+
"4. You should probably make \\#3 a function called `distance` that takes four parameters (`x1`, `x2`, `y1`, `y2`) and returns the distance.\n",
478482
"5. Now that you have your distance formula see if you can make your program say 'warmer' or 'colder' depending on if their distance is closer or further from the treasure than last time (remember to store the last time).\n",
479483
"6. You might want to add some error checking for if the user say something besides N, S, E, W, or done. "
480484
]
@@ -505,7 +509,7 @@
505509
"name": "python",
506510
"nbconvert_exporter": "python",
507511
"pygments_lexer": "ipython2",
508-
"version": "2.7.10"
512+
"version": "2.7.11"
509513
}
510514
},
511515
"nbformat": 4,

0 commit comments

Comments
 (0)