|
31 | 31 | "source": [ |
32 | 32 | "my_string = \"Howdy, welcome to my ranch?\"\n", |
33 | 33 | "\n", |
34 | | - "print len(my_string)\n", |
35 | | - "print max(my_string)\n", |
36 | | - "print min(my_string)" |
| 34 | + "print(len(my_string))\n", |
| 35 | + "print(max(my_string))\n", |
| 36 | + "print(min(my_string))" |
37 | 37 | ] |
38 | 38 | }, |
39 | 39 | { |
|
76 | 76 | }, |
77 | 77 | "outputs": [], |
78 | 78 | "source": [ |
79 | | - "print int('5')\n", |
80 | | - "print float(5)\n", |
81 | | - "print str(5)\n", |
82 | | - "print bool(1)\n", |
| 79 | + "print(int('5'))\n", |
| 80 | + "print(float(5))\n", |
| 81 | + "print(str(5))\n", |
| 82 | + "print(bool(1))\n", |
83 | 83 | "\n", |
84 | 84 | "# Uh-Oh\n", |
85 | | - "print int('five')" |
| 85 | + "print(int('five'))" |
86 | 86 | ] |
87 | 87 | }, |
88 | 88 | { |
|
129 | 129 | "import random\n", |
130 | 130 | "\n", |
131 | 131 | "#Your value should be different from mine.\n", |
132 | | - "print random.random()" |
| 132 | + "random.random()" |
133 | 133 | ] |
134 | 134 | }, |
135 | 135 | { |
|
151 | 151 | }, |
152 | 152 | "outputs": [], |
153 | 153 | "source": [ |
154 | | - "print random.randint(5,7)" |
| 154 | + "random.randint(5,7)" |
155 | 155 | ] |
156 | 156 | }, |
157 | 157 | { |
|
213 | 213 | "# using constant\n", |
214 | 214 | "radius = 5\n", |
215 | 215 | "circumference = math.pi * 2 * radius\n", |
216 | | - "print circumference\n", |
| 216 | + "print(circumference)\n", |
217 | 217 | "\n", |
218 | 218 | "# using functions\n", |
219 | | - "print math.sin(0)\n", |
220 | | - "print math.cos(0)" |
| 219 | + "print(math.sin(0))\n", |
| 220 | + "print(math.cos(0))" |
221 | 221 | ] |
222 | 222 | }, |
223 | 223 | { |
|
263 | 263 | "outputs": [], |
264 | 264 | "source": [ |
265 | 265 | "def yeehaw():\n", |
266 | | - " print \"YEEHAW\"\n", |
| 266 | + " print(\"YEEHAW\")\n", |
267 | 267 | " \n", |
268 | 268 | "#notice that nothing is printed, the functions is not run unless you call it" |
269 | 269 | ] |
|
297 | 297 | "source": [ |
298 | 298 | "def cowgirl():\n", |
299 | 299 | " yeehaw()\n", |
300 | | - " print \"I'm gonna lasso me some cattle\"\n", |
| 300 | + " print(\"I'm gonna lasso me some cattle\")\n", |
301 | 301 | " yeehaw()\n", |
302 | 302 | " \n", |
303 | 303 | "# Got to run it\n", |
|
330 | 330 | "You can have your function take one or more variables as input, these are called arguments. Arguments are assigned to parameters (named variables). You can use the parameters inside the body of the function\n", |
331 | 331 | "\n", |
332 | 332 | " def myfunc(parameter1, parameter2):\n", |
333 | | - " print parameter1\n", |
| 333 | + " print(parameter1)\n", |
334 | 334 | " \n", |
335 | 335 | " myfunc('hello', 'goodbye')\n", |
336 | 336 | " \n", |
|
348 | 348 | "source": [ |
349 | 349 | "def feed_animal(type_of_feed):\n", |
350 | 350 | " if type_of_feed == 'oats':\n", |
351 | | - " print \"Feeding the horse\"\n", |
| 351 | + " print(\"Feeding the horse\")\n", |
352 | 352 | " elif type_of_feed == 'hay':\n", |
353 | | - " print \"Feeding the cows\"\n", |
| 353 | + " print(\"Feeding the cows\")\n", |
354 | 354 | " else:\n", |
355 | | - " print \"Feeding the pigs\"\n", |
| 355 | + " print(\"Feeding the pigs\")\n", |
356 | 356 | " \n", |
357 | 357 | "feed_animal('hay')\n", |
358 | 358 | "\n", |
|
392 | 392 | " return \"Hello\"\n", |
393 | 393 | " \n", |
394 | 394 | " greeting = myfunction()\n", |
395 | | - " print myfunction() + \" , world\"" |
| 395 | + " print(myfunction() + \" , world\")" |
396 | 396 | ] |
397 | 397 | }, |
398 | 398 | { |
|
410 | 410 | " elif type_of_feed == 'corn':\n", |
411 | 411 | " cost = 5\n", |
412 | 412 | " elif type_of_feed == 'grass':\n", |
413 | | - " return 0\n", |
| 413 | + " cost = 0\n", |
414 | 414 | " return cost\n", |
415 | 415 | "\n", |
416 | 416 | "oats_cost = cost_of_feed('oats')\n", |
417 | 417 | "\n", |
418 | 418 | "# Now I can use this value\n", |
419 | 419 | "oats_for_farm = 150 * oats_cost\n", |
420 | | - "print \"It costs \" + str(oats_for_farm) + \" to feed 150 horse\"" |
| 420 | + "print(\"It costs \" + str(oats_for_farm) + \" to feed 150 horse\")" |
421 | 421 | ] |
422 | 422 | }, |
423 | 423 | { |
|
480 | 480 | } |
481 | 481 | ], |
482 | 482 | "metadata": { |
| 483 | + "anaconda-cloud": {}, |
483 | 484 | "kernelspec": { |
484 | | - "display_name": "Python 2", |
| 485 | + "display_name": "Python [default]", |
485 | 486 | "language": "python", |
486 | | - "name": "python2" |
| 487 | + "name": "python3" |
487 | 488 | }, |
488 | 489 | "language_info": { |
489 | 490 | "codemirror_mode": { |
490 | 491 | "name": "ipython", |
491 | | - "version": 2 |
| 492 | + "version": 3 |
492 | 493 | }, |
493 | 494 | "file_extension": ".py", |
494 | 495 | "mimetype": "text/x-python", |
495 | 496 | "name": "python", |
496 | 497 | "nbconvert_exporter": "python", |
497 | | - "pygments_lexer": "ipython2", |
498 | | - "version": "2.7.11" |
| 498 | + "pygments_lexer": "ipython3", |
| 499 | + "version": "3.5.2" |
499 | 500 | } |
500 | 501 | }, |
501 | 502 | "nbformat": 4, |
|
0 commit comments