summaryrefslogtreecommitdiff
path: root/Beginning_C++_through_Game_Programming/ch5.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/ch5.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/ch5.ipynb')
-rwxr-xr-xBeginning_C++_through_Game_Programming/ch5.ipynb229
1 files changed, 229 insertions, 0 deletions
diff --git a/Beginning_C++_through_Game_Programming/ch5.ipynb b/Beginning_C++_through_Game_Programming/ch5.ipynb
new file mode 100755
index 00000000..a55d763d
--- /dev/null
+++ b/Beginning_C++_through_Game_Programming/ch5.ipynb
@@ -0,0 +1,229 @@
+{
+ "metadata": {
+ "name": "ch5"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": "Chapter 5 : Fruitful functions"
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": "example 5.1 page no :41\n"
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": "'''\nexample 5.1 page no :41\n'''\nimport math\ndef area (radius):\n area = math.pi * radius * radius;\n return area;\n\nprint area(3)",
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": "28.2743338823\n"
+ }
+ ],
+ "prompt_number": 1
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": "example 5.2 page no :42\n"
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": "'''\nexample 5.2 page no :42\n'''\n\ndef absoluteValue (x):\n if (x < 0):\n return -x\n else:\n return x\n\nprint absoluteValue(-3) \nprint absoluteValue(3)",
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": "3\n3\n"
+ }
+ ],
+ "prompt_number": 2
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": "example 5.3 page no :44\n"
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": "'''\nexample 5.3 page no :44\n'''\n\ndef distance (x1, y1,x2,y2):\n dx = x2 - x1\n dy = y2 - y1;\n print \"dx is \" , dx\n print \"dy is \" , dy \n return 0.0\n\ndistance(10,10,20,20) ",
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": "dx is 10\ndy is 10\n"
+ },
+ {
+ "metadata": {},
+ "output_type": "pyout",
+ "prompt_number": 3,
+ "text": "0.0"
+ }
+ ],
+ "prompt_number": 3
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": "example 5.4 page no :44\n"
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": "'''\nexample 5.4 page no :44\n'''\n\ndef distance (x1, y1,x2,y2):\n dx = x2 - x1\n dy = y2 - y1;\n dsquared = dx*dx + dy*dy;\n print \"dsquared is \" , dsquared\n return 0.0;\n\ndistance(10,10,20,20)",
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": "dsquared is 200\n"
+ },
+ {
+ "metadata": {},
+ "output_type": "pyout",
+ "prompt_number": 4,
+ "text": "0.0"
+ }
+ ],
+ "prompt_number": 4
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": "example 5.5 page no :45\n"
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": "'''\nexample 5.5 page no :45\n'''\nimport math\ndef distance (x1, y1,x2,y2):\n dx = x2 - x1\n dy = y2 - y1;\n dsquared = dx*dx + dy*dy;\n return math.sqrt(dsquared)\n \nprint distance(10,10,20,20)",
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": "14.1421356237\n"
+ }
+ ],
+ "prompt_number": 5
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": "example 5.6 page no :45\n"
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": "'''\nexample 5.6 page no :45\n'''\n\nimport math\ndef area (radius):\n area = math.pi * radius * radius;\n return area;\n\ndef distance (x1, y1,x2,y2):\n dx = x2 - x1\n dy = y2 - y1;\n dsquared = dx*dx + dy*dy;\n return math.sqrt(dsquared)\n \ndef fred(xc, yc, xp,yp):\n radius = distance (xc, yc, xp, yp);\n result = area (radius);\n return result;\n\nprint fred(10,10,20,20)",
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": "628.318530718\n"
+ }
+ ],
+ "prompt_number": 6
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": "example 5.7 page no :48\n"
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": "'''\nexample 5.7 page no :48\n'''\ndef isSingleDigit(x):\n if (x >= 0 and x < 10):\n return True\n else:\n return False;\n\nprint isSingleDigit(11)\nprint isSingleDigit(4)",
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": "False\nTrue\n"
+ }
+ ],
+ "prompt_number": 7
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": "example 5.8 page no :51/53\n"
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": "'''\nexample 5.8 page no :51/53\n'''\n\ndef factorial (n):\n if (n == 0):\n return 1;\n else:\n recurse = factorial (n-1)\n result = n * recurse\n return result;\n\nprint factorial(5)",
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": "120\n"
+ }
+ ],
+ "prompt_number": 8
+ },
+ {
+ "cell_type": "heading",
+ "level": 3,
+ "metadata": {},
+ "source": "example 5.9 page no :53\n"
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": "'''\nexample 5.9 page no :53\n'''\ndef fibonacci (n):\n if (n == 0 or n == 1):\n return 1\n else:\n return fibonacci (n-1) + fibonacci (n-2)\n\nprint fibonacci(5)",
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": "8\n"
+ }
+ ],
+ "prompt_number": 9
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": "",
+ "language": "python",
+ "metadata": {},
+ "outputs": []
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file