summaryrefslogtreecommitdiff
path: root/Beginning_C++_through_Game_Programming/ch6.ipynb
diff options
context:
space:
mode:
authorJovina Dsouza2014-07-07 16:34:28 +0530
committerJovina Dsouza2014-07-07 16:34:28 +0530
commitfffcc90da91b66ee607066d410b57f34024bd1de (patch)
tree7b8011d61013305e0bf7794a275706abd1fdb0d3 /Beginning_C++_through_Game_Programming/ch6.ipynb
parent299711403e92ffa94a643fbd960c6f879639302c (diff)
downloadPython-Textbook-Companions-fffcc90da91b66ee607066d410b57f34024bd1de.tar.gz
Python-Textbook-Companions-fffcc90da91b66ee607066d410b57f34024bd1de.tar.bz2
Python-Textbook-Companions-fffcc90da91b66ee607066d410b57f34024bd1de.zip
adding book
Diffstat (limited to 'Beginning_C++_through_Game_Programming/ch6.ipynb')
-rwxr-xr-xBeginning_C++_through_Game_Programming/ch6.ipynb265
1 files changed, 265 insertions, 0 deletions
diff --git a/Beginning_C++_through_Game_Programming/ch6.ipynb b/Beginning_C++_through_Game_Programming/ch6.ipynb
new file mode 100755
index 00000000..3b13a110
--- /dev/null
+++ b/Beginning_C++_through_Game_Programming/ch6.ipynb
@@ -0,0 +1,265 @@
+{
+ "metadata": {
+ "name": "ch6"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": "Chapter 6 : Iteration"
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": "example 6.1 page no :56\n"
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": "'''\nexample 6.1 page no :56\n'''\n\ndef countdown (n):\n while (n > 0):\n print n\n n = n-1\n print \"Blastoff!\"\n return 0\n \ncountdown(5) ",
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": "5\n4\n3\n2\n1\nBlastoff!\n"
+ },
+ {
+ "metadata": {},
+ "output_type": "pyout",
+ "prompt_number": 1,
+ "text": "0"
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": "example 6.2 page no :57\n"
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": "'''\nexample 6.2 page no :57\n'''\n\ndef sequence (n):\n while (n != 1):\n print n\n if (n%2 == 0):\n n = n / 2\n else:\n n = n*3 + 1\n \nsequence(10)",
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": "10\n5\n16\n8\n4\n2\n"
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": "example 6.3 page no :58\n"
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": "'''\nexample 6.3 page no :58\n'''\nimport math\nx = 1.0\nwhile (x < 10.0):\n print x , \"\\t\" , math.log(x)\n x = x + 1.0",
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": "1.0 \t0.0\n2.0 \t0.69314718056\n3.0 \t1.09861228867\n4.0 \t1.38629436112\n5.0 \t1.60943791243\n6.0 \t1.79175946923\n7.0 \t1.94591014906\n8.0 \t2.07944154168\n9.0 \t2.19722457734\n"
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": "example 6.4 page no :59\n"
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": "'''\nexample 6.4 page no :59\n'''\nimport math\nx = 1.0\nwhile (x < 10.0):\n print x , \"\\t\" , math.log(x) / math.log(2.0) \n x = x + 1.0\n\n",
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": "1.0 \t0.0\n2.0 \t1.0\n3.0 \t1.58496250072\n4.0 \t2.0\n5.0 \t2.32192809489\n6.0 \t2.58496250072\n7.0 \t2.80735492206\n8.0 \t3.0\n9.0 \t3.16992500144\n"
+ }
+ ],
+ "prompt_number": 4
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": "example 6.5 page no :59\n"
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": "'''\nexample 6.5 page no :59\n'''\nimport math\nx = 1.0;\nwhile (x < 100.0):\n print x , \"\\t\" , math.log(x) / math.log(2.0)\n x = x * 2.0",
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": "1.0 \t0.0\n2.0 \t1.0\n4.0 \t2.0\n8.0 \t3.0\n16.0 \t4.0\n32.0 \t5.0\n64.0 \t6.0\n"
+ }
+ ],
+ "prompt_number": 5
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": "example 6.6 page no: 60\n"
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": "'''\nexample 6.6 page no: 60\n'''\n\ni = 1;\nwhile (i <= 6):\n print 2*i ,\n i = i + 1;\n",
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": "2 4 6 8 10 12\n"
+ }
+ ],
+ "prompt_number": 6
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": "example 6.7 page no:60\n"
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": "'''\nexample 6.7 page no:60\n'''\n\ndef printMultiples (n):\n i = 1\n while (i <= 6):\n print n*i,\n i = i + 1;\n \nprintMultiples(3) ",
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": "3 6 9 12 15 18\n"
+ }
+ ],
+ "prompt_number": 7
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": "example 6.8 page no:61\n"
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": "'''\nexample 6.8 page no:61\n'''\n\n\ndef printMultiples (n):\n i = 1\n while (i <= 6):\n print n*i,\n i = i + 1;\n print '' \n\ni = 1;\nwhile (i <= 6):\n printMultiples (i);\n i = i + 1;",
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": "1 2 3 4 5 6 \n2 4 6 8 10 12 \n3 6 9 12 15 18 \n4 8 12 16 20 24 \n5 10 15 20 25 30 \n6 12 18 24 30 36 \n"
+ }
+ ],
+ "prompt_number": 8
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": "example 6.9 page no: 62\n"
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": "'''\nexample 6.9 page no: 62\n'''\n\ndef printMultiples (n):\n i = 1\n while (i <= 6):\n print n*i,\n i = i + 1;\n print '' \n\ndef printMultTable ():\n i = 1;\n while (i <= 6):\n printMultiples (i)\n i = i + 1\n\nprintMultTable()",
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": "1 2 3 4 5 6 \n2 4 6 8 10 12 \n3 6 9 12 15 18 \n4 8 12 16 20 24 \n5 10 15 20 25 30 \n6 12 18 24 30 36 \n"
+ }
+ ],
+ "prompt_number": 9
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": "example 6.10 page no :63\n"
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": "'''\nexample 6.10 page no :63\n'''\n\ndef printMultiples (n):\n i = 1\n while (i <= 6):\n print n*i,\n i = i + 1;\n print '' \n\ndef printMultTable (high):\n i = 1;\n while (i <= high):\n printMultiples (i);\n i = i + 1;\n \nprintMultTable(4) ",
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": "1 2 3 4 5 6 \n2 4 6 8 10 12 \n3 6 9 12 15 18 \n4 8 12 16 20 24 \n"
+ }
+ ],
+ "prompt_number": 10
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": "example 6.11 page no :64\n"
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": "'''\nexample 6.11 page no :64\n'''\n\ndef printMultiples(n,high):\n i = 1;\n while (i <= high):\n print n*i ,\n i = i + 1;\n print ''\n\ndef printMultTable (high):\n i = 1; \n while (i <= high):\n printMultiples (i, high)\n i = i + 1;\n\nprintMultTable(5) ",
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": "1 2 3 4 5 \n2 4 6 8 10 \n3 6 9 12 15 \n4 8 12 16 20 \n5 10 15 20 25 \n"
+ }
+ ],
+ "prompt_number": 11
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": "",
+ "language": "python",
+ "metadata": {},
+ "outputs": []
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file