From 5a86a20b9de487553d4ef88719fb0fd76a5dd6a7 Mon Sep 17 00:00:00 2001 From: hardythe1 Date: Fri, 3 Jul 2015 12:23:43 +0530 Subject: add/remove books --- .../Chapter5.ipynb | 209 +++++++++++++++++++++ 1 file changed, 209 insertions(+) create mode 100755 C_Programming:_A_Modern_Approach_by_K.N._King/Chapter5.ipynb (limited to 'C_Programming:_A_Modern_Approach_by_K.N._King/Chapter5.ipynb') diff --git a/C_Programming:_A_Modern_Approach_by_K.N._King/Chapter5.ipynb b/C_Programming:_A_Modern_Approach_by_K.N._King/Chapter5.ipynb new file mode 100755 index 00000000..c7353250 --- /dev/null +++ b/C_Programming:_A_Modern_Approach_by_K.N._King/Chapter5.ipynb @@ -0,0 +1,209 @@ +{ + "metadata": { + "name": "", + "signature": "sha256:e0e8d285e21d88c99025668fa4fa5ab37c188ffb30c516ae4e90ff1d9747226e" + }, + "nbformat": 3, + "nbformat_minor": 0, + "worksheets": [ + { + "cells": [ + { + "cell_type": "heading", + "level": 1, + "metadata": {}, + "source": [ + "Chapter 5: Selection Statements" + ] + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example broker.c on Page 81" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "def main():\n", + " commission=0.0 #variable declaration\n", + " value=float(raw_input(\"Enter value of trade: \")) #accepting the trade value\n", + " \n", + " #calculating commission according to the value of trade\n", + " if(value < 2500.00):\n", + " commission = 30.00 + 0.017 * value\n", + " elif (value < 6250.00):\n", + " commission = 56.00 + 0.0066 * value\n", + " elif (value < 20000.00):\n", + " commission = 76.00 + 0.0034 * value\n", + " elif (value < 50000.00):\n", + " commission = 100.00 + 0.0022 * value\n", + " elif (value < 500000.00):\n", + " commission = 155.00 + 0.0011 * value\n", + " else:\n", + " commission = 255.00 + 0.0009 * value\n", + " \n", + " if (commission < 39.00):\n", + " commission = 39.00\n", + " \n", + " print \"Commission: $%0.2f\" % commission #printing the value of commission\n", + "\n", + "if __name__=='__main__':\n", + " main()" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "Enter value of trade: 7000.00\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Commission: $99.80\n" + ] + } + ], + "prompt_number": 1 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example on Page 83" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "def main():\n", + " #variable declaration\n", + " i=1\n", + " j=2\n", + " \n", + " if(i>j): #k=i>j?i:j\n", + " k=i \n", + " else: \n", + " k=j #k is now 2\n", + " \n", + " if(i>=0): #k=(i>=0?i:0)+j\n", + " k=i+j #k is now 3\n", + " else:\n", + " k=0+j\n", + "if __name__=='__main__':\n", + " main()" + ], + "language": "python", + "metadata": {}, + "outputs": [], + "prompt_number": 1 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "Example date.c on Page 89" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "def main():\n", + " date=raw_input(\"Enter date (mm/dd/yy): \") #accepting the date in mm/dd/yy format\n", + " date1=date.split(\"/\")\n", + " #day, moth and year separation\n", + " day=int(date1[1])\n", + " month= int(date1[0])\n", + " year=int(date1[2])\n", + " \n", + " #printing day as an ordinal number\n", + " print \"Dated this\", day,\n", + " if (day==1 or day==21 or day==31):\n", + " print \"st\",\n", + " elif (day==2 or day==22):\n", + " print \"nd\",\n", + " elif (day==3 or day==23):\n", + " print \"rd\",\n", + " else:\n", + " print \"th\",\n", + " print \"day of\",\n", + " \n", + " #printing month\n", + " if (month==1):\n", + " print \"January\",\n", + " elif(month==2):\n", + " print \"February\",\n", + " elif(month==3):\n", + " print \"March\",\n", + " elif(month==4):\n", + " print \"April\",\n", + " elif(month==5):\n", + " print \"May\",\n", + " elif(month==6):\n", + " print \"June\",\n", + " elif(month==7):\n", + " print \"July\",\n", + " elif(month==8):\n", + " print \"August\",\n", + " elif(month==9):\n", + " print \"September\",\n", + " elif(month==10):\n", + " print \"October\",\n", + " elif(month==11):\n", + " print \"November\",\n", + " elif(month==12):\n", + " print \"December\",\n", + " \n", + " #printing year\n", + " print \", 20%0.2d.\" % year\n", + " \n", + "if __name__=='__main__':\n", + " main()" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "Enter date (mm/dd/yy): 7/19/14\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Dated this 19 th day of July , 2014.\n" + ] + } + ], + "prompt_number": 1 + }, + { + "cell_type": "code", + "collapsed": false, + "input": [], + "language": "python", + "metadata": {}, + "outputs": [] + } + ], + "metadata": {} + } + ] +} \ No newline at end of file -- cgit