diff options
author | hardythe1 | 2015-04-07 15:58:05 +0530 |
---|---|---|
committer | hardythe1 | 2015-04-07 15:58:05 +0530 |
commit | c7fe425ef3c5e8804f2f5de3d8fffedf5e2f1131 (patch) | |
tree | 725a7d43dc1687edf95bc36d39bebc3000f1de8f /Computer_Programming_Theory_and_Practice/Chapter3.ipynb | |
parent | 62aa228e2519ac7b7f1aef53001f2f2e988a6eb1 (diff) | |
download | Python-Textbook-Companions-c7fe425ef3c5e8804f2f5de3d8fffedf5e2f1131.tar.gz Python-Textbook-Companions-c7fe425ef3c5e8804f2f5de3d8fffedf5e2f1131.tar.bz2 Python-Textbook-Companions-c7fe425ef3c5e8804f2f5de3d8fffedf5e2f1131.zip |
added books
Diffstat (limited to 'Computer_Programming_Theory_and_Practice/Chapter3.ipynb')
-rwxr-xr-x | Computer_Programming_Theory_and_Practice/Chapter3.ipynb | 293 |
1 files changed, 293 insertions, 0 deletions
diff --git a/Computer_Programming_Theory_and_Practice/Chapter3.ipynb b/Computer_Programming_Theory_and_Practice/Chapter3.ipynb new file mode 100755 index 00000000..04d24871 --- /dev/null +++ b/Computer_Programming_Theory_and_Practice/Chapter3.ipynb @@ -0,0 +1,293 @@ +{ + "metadata": { + "name": "", + "signature": "sha256:0ff7bb47f00bae9dc5a49237df7011debd17443ba836341d55e8fe830338ade7" + }, + "nbformat": 3, + "nbformat_minor": 0, + "worksheets": [ + { + "cells": [ + { + "cell_type": "heading", + "level": 1, + "metadata": {}, + "source": [ + "Chapter 3: Input/Output Functions and Statements" + ] + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 1 , Page number: CP-39" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#program to add and find product of two numbers\n", + "\n", + "#variable declaration\n", + "a = 5\n", + "b = 3\n", + "\n", + "# calculation of sum and product \n", + "\n", + "summ = a + b\n", + "product = a * b\n", + "\n", + "print a,b\n", + "print summ,product" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "5 3\n", + "8 15\n" + ] + } + ], + "prompt_number": 1 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 2 , Page number: CP-45" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "# Program to convert degree fahrenheit to celcius \n", + "# variable declaration\n", + "\n", + "f = 105.00\n", + "print \"Degree fahrenheit ? %d\" % f\n", + "# calculation of degree in celcius \n", + "\n", + "c = 5.0/9.0 * (f-32)\n", + "\n", + "# result \n", + "print\n", + "print \"Degree centigrade =%6.2f\" % c" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Degree fahrenheit ? 105\n", + "\n", + "Degree centigrade = 40.56\n" + ] + } + ], + "prompt_number": 2 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 3 , Page number: CP-45" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "# To find area of a triangle\n", + "# variable declaration\n", + "\n", + "a = 5\n", + "b = 4\n", + "c = 6\n", + "\n", + "\n", + "# calculation of area\n", + "s = float((a+b+c))/2\n", + "area = (s*(s-a)*(s-b)*(s-c)) ** 0.5\n", + "\n", + "# result\n", + "print \"Enter three sides : %d\" % a,b,c\n", + "print \n", + "print \"Area of triangle = %0.2f Sq.units\" % area" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Enter three sides : 5 4 6\n", + "\n", + "Area of triangle = 9.92 Sq.units\n" + ] + } + ], + "prompt_number": 4 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 4 , Page number: CP-51" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "# To print ASCII value of a given character \n", + "# Variable declaration\n", + "\n", + "ch = \"A\"\n", + "print \"Enter a character : \" , ch\n", + "\n", + "# Calculation of ASCII value of a character\n", + "\n", + "print \n", + "print \"ASCII value of \" + ch + \" is\" ,ord(ch)\n", + "print \"Press any key to stop. . .\"" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Enter a character : A\n", + "\n", + "ASCII value of A is 65\n", + "Press any key to stop. . .\n" + ] + } + ], + "prompt_number": 5 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 5 , Page number: CP-51" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "# To print electricity for consumers\n", + "# Variable declaration\n", + "\n", + "sno = \"TMR65358\"\n", + "pmr = 4305\n", + "cmr = 4410\n", + "\n", + "print \"Enter service number :\" ,sno\n", + "print \"Previous meter reading ?\",pmr\n", + "print \"Current meter reading ?\",cmr\n", + "\n", + "# Calculation of electricity charges\n", + "\n", + "units = cmr - pmr\n", + "amt = units * 1.50\n", + "\n", + "# Result\n", + "\n", + "print\n", + "print \" Electricity Bill\"\n", + "print \" ----------------\"\n", + "print \"Service No :\",sno\n", + "print \"Unit Consumed :\",units\n", + "print \"Electricity Charges : Rs.%0.2f\" % amt" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Enter service number : TMR65358\n", + "Previous meter reading ? 4305\n", + "Current meter reading ? 4410\n", + "\n", + " Electricity Bill\n", + " ----------------\n", + "Service No : TMR65358\n", + "Unit Consumed : 105\n", + "Electricity Charges : Rs.157.50\n" + ] + } + ], + "prompt_number": 6 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example 6 , Page number: CP-52" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "# Program to swap value of two variables\n", + "# Variable declaration\n", + "\n", + "a = 15\n", + "b = 250 \n", + "\n", + "print \"Enter value to A :\",a\n", + "print \"Enter value to B :\",b\n", + "\n", + "# Swapping\n", + "\n", + "temp = a\n", + "a = b\n", + "b = temp\n", + "\n", + "print \n", + "print \"Value of A =\",a\n", + "print \"Value of B =\",b" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Enter value to A : 15\n", + "Enter value to B : 250\n", + "\n", + "Value of A = 250\n", + "Value of B = 15\n" + ] + } + ], + "prompt_number": 7 + } + ], + "metadata": {} + } + ] +}
\ No newline at end of file |