summaryrefslogtreecommitdiff
path: root/Teach_Yourself_C_in_24_Hours/hour6.ipynb
diff options
context:
space:
mode:
Diffstat (limited to 'Teach_Yourself_C_in_24_Hours/hour6.ipynb')
-rwxr-xr-xTeach_Yourself_C_in_24_Hours/hour6.ipynb211
1 files changed, 211 insertions, 0 deletions
diff --git a/Teach_Yourself_C_in_24_Hours/hour6.ipynb b/Teach_Yourself_C_in_24_Hours/hour6.ipynb
new file mode 100755
index 00000000..a23d8d29
--- /dev/null
+++ b/Teach_Yourself_C_in_24_Hours/hour6.ipynb
@@ -0,0 +1,211 @@
+{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:e529cfbc85bce112cc77323c9cb2b301f79e8cbceaba58360ccb33809ec1b0e2"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "HOUR 6 : Manipulating Data"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 6.1, Page No 94"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "x = 1\n",
+ "y = 3\n",
+ "z = 10\n",
+ "print \"Given \" ,x,y,z,\"\\n\"\n",
+ "x = x + y\n",
+ "print \"x = x + y assigns \" + str(x) + \"to x\\n\"\n",
+ "x = 1\n",
+ "x += y\n",
+ "print \"x += y assigns \" + str(x) + \"to x\\n\"\n",
+ "x = 1\n",
+ "z = z * x + y\n",
+ "print \"z = z * x + y assigns\" + str(z) + \"to z\\n\"\n",
+ "z = 10\n",
+ "z = z * (x + y)\n",
+ "print \"z = z * (x + y) assigns\" + str(z) + \"to z\\n\"\n",
+ "z = 10\n",
+ "z *= x + y\n",
+ "print \"z *= x + y assigns\" + str(z) + \"to z\\n\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Given 1 3 10 \n",
+ "\n",
+ "x = x + y assigns 4to x\n",
+ "\n",
+ "x += y assigns 4to x\n",
+ "\n",
+ "z = z * x + y assigns13to z\n",
+ "\n",
+ "z = z * (x + y) assigns40to z\n",
+ "\n",
+ "z *= x + y assigns40to z\n",
+ "\n"
+ ]
+ }
+ ],
+ "prompt_number": 8
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 6.2, Page No 97"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "#there is no concept of pre-increment or post-increment in Python.\n",
+ "w=x=y=z=1\n",
+ "print \"Given w = \",w,\"x = \",x,\"y = \",y,\"z = \",z,\"\\n\"\n",
+ "w+=1\n",
+ "result=w\n",
+ "print \"++w evaluates to \" ,result,\"and w is now \",w,\"\\n\"\n",
+ "result = x\n",
+ "x = x + 1\n",
+ "print \"x++ evaluates to \",result,\" and x is now \",x,\"\\n\"\n",
+ "y-=1\n",
+ "result = y\n",
+ "print \"--y evaluates to \",result,\" and y is now \",y,\"\\n\"\n",
+ "result = z\n",
+ "z -= 1\n",
+ "print \"z-- evaluates to \",result,\" and z is now \",z,\"\\n\""
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Given w = 1 x = 1 y = 1 z = 1 \n",
+ "\n",
+ "++w evaluates to 2 and w is now 2 \n",
+ "\n",
+ "x++ evaluates to 1 and x is now 2 \n",
+ "\n",
+ "--y evaluates to 0 and y is now 0 \n",
+ "\n",
+ "z-- evaluates to 1 and z is now 0 \n",
+ "\n"
+ ]
+ }
+ ],
+ "prompt_number": 5
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 6.3, Page No 99"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "x = 7\n",
+ "y = 25\n",
+ "z = 24.46\n",
+ "print \"Given x = \",x,\"y = \",y,\" and z = \",z,\"\\n\"\n",
+ "print \"x >= y produces: \",x >= y,\"\\n\"\n",
+ "print \"x == y produces: \",x == y,\"\\n\"\n",
+ "print \"x < z produces: \",x < z,\"\\n\"\n",
+ "print \"y > z produces: \",y > z,\"\\n\"\n",
+ "print \"x != y - 18 produces: \",x != y - 18,\"\\n\"\n",
+ "print \"x + y != z produces: \",x + y != z"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Given x = 7 y = 25 and z = 24.46 \n",
+ "\n",
+ "x >= y produces: False \n",
+ "\n",
+ "x == y produces: False \n",
+ "\n",
+ "x < z produces: True \n",
+ "\n",
+ "y > z produces: True \n",
+ "\n",
+ "x != y - 18 produces: False \n",
+ "\n",
+ "x + y != z produces: True\n"
+ ]
+ }
+ ],
+ "prompt_number": 9
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example 6.4, Page No 101"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "x = 7\n",
+ "y = 5\n",
+ "print \"Given x = \",x,\"y = \",y,\"\\n\"\n",
+ "print \"x / y produces: \",x/y,\"\\n\"\n",
+ "print \"(float)x / y produces: \", float(x)/y"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Given x = 7 y = 5 \n",
+ "\n",
+ "x / y produces: 1 \n",
+ "\n",
+ "(float)x / y produces: 1.4\n"
+ ]
+ }
+ ],
+ "prompt_number": 10
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+} \ No newline at end of file