diff options
author | hardythe1 | 2015-07-03 12:23:43 +0530 |
---|---|---|
committer | hardythe1 | 2015-07-03 12:23:43 +0530 |
commit | 5a86a20b9de487553d4ef88719fb0fd76a5dd6a7 (patch) | |
tree | db67ac5738a18b921d9a8cf6e86f402703f30bdf /C_Programming:_A_Modern_Approach_by_K.N._King/Chapter13.ipynb | |
parent | 37d315828bbfc0f5cabee669d2b9dd8cd17b5154 (diff) | |
download | Python-Textbook-Companions-5a86a20b9de487553d4ef88719fb0fd76a5dd6a7.tar.gz Python-Textbook-Companions-5a86a20b9de487553d4ef88719fb0fd76a5dd6a7.tar.bz2 Python-Textbook-Companions-5a86a20b9de487553d4ef88719fb0fd76a5dd6a7.zip |
add/remove books
Diffstat (limited to 'C_Programming:_A_Modern_Approach_by_K.N._King/Chapter13.ipynb')
-rwxr-xr-x | C_Programming:_A_Modern_Approach_by_K.N._King/Chapter13.ipynb | 127 |
1 files changed, 127 insertions, 0 deletions
diff --git a/C_Programming:_A_Modern_Approach_by_K.N._King/Chapter13.ipynb b/C_Programming:_A_Modern_Approach_by_K.N._King/Chapter13.ipynb new file mode 100755 index 00000000..03c83450 --- /dev/null +++ b/C_Programming:_A_Modern_Approach_by_K.N._King/Chapter13.ipynb @@ -0,0 +1,127 @@ +{
+ "metadata": {
+ "name": "",
+ "signature": "sha256:00fb09fcd8819c39a88f9cac94eaa93d1e9e72c864c95cc17c2c19aa93c94143"
+ },
+ "nbformat": 3,
+ "nbformat_minor": 0,
+ "worksheets": [
+ {
+ "cells": [
+ {
+ "cell_type": "heading",
+ "level": 1,
+ "metadata": {},
+ "source": [
+ "Chapter 13: Strings"
+ ]
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example remind.c, Page 294"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "MAX_REMIND=50\n",
+ "MSG_LEN=60\n",
+ "reminders = [['' for i in xrange(MSG_LEN+3)] for i in xrange(MAX_REMIND)]\n",
+ "num_remind=0\n",
+ "while(1):\n",
+ " if(num_remind==MAX_REMIND):\n",
+ " print \"--No space left --\"\n",
+ " break\n",
+ " li=raw_input( \"Enter day and reminder: \")\n",
+ " li1=li.split()\n",
+ " day_str=li1[0]\n",
+ " if(day_str=='0'):\n",
+ " break\n",
+ " msg_str=li1[1:]\n",
+ " i=0\n",
+ " for i in range(num_remind):\n",
+ " if(day_str<reminders[i]):\n",
+ " break\n",
+ " j=num_remind\n",
+ " while(j>i):\n",
+ " reminders[j]=reminders[j-1]\n",
+ " j=j-1\n",
+ " reminders[i]=day_str\n",
+ " reminders[i]=str(reminders[i])+str(msg_str)\n",
+ " \n",
+ " num_remind=num_remind+1\n",
+ "print \"\"\n",
+ "print \"Day Reminder\"\n",
+ "for i in range(num_remind):\n",
+ " print \"%s\"%reminders[i]"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": []
+ },
+ {
+ "cell_type": "heading",
+ "level": 2,
+ "metadata": {},
+ "source": [
+ "Example planet.c, Page 303"
+ ]
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [
+ "NUM_PLANETS=9\n",
+ "li=raw_input()\n",
+ "argv=li.split()\n",
+ "planets=['Mercury','Venus','Earth','Mars','Jupiter','Saturn','Uranus','Neptune','Pluto']\n",
+ "argc=len(argv)\n",
+ "for i in range(argc-1):\n",
+ " for j in range(NUM_PLANETS):\n",
+ " if( argv[i+1]==planets[j]):\n",
+ " print \"%s is a planet %d\"%(argv[i+1],(j+1))\n",
+ " break\n",
+ " if(argv[i] not in planets):\n",
+ " print \"%s is not a planet\"%argv[i]"
+ ],
+ "language": "python",
+ "metadata": {},
+ "outputs": [
+ {
+ "name": "stdout",
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "planet Jupiter Venus Earth fred\n"
+ ]
+ },
+ {
+ "output_type": "stream",
+ "stream": "stdout",
+ "text": [
+ "Jupiter is a planet 5\n",
+ "planet is not a planet\n",
+ "Venus is a planet 2\n",
+ "Earth is a planet 3\n"
+ ]
+ }
+ ],
+ "prompt_number": 5
+ },
+ {
+ "cell_type": "code",
+ "collapsed": false,
+ "input": [],
+ "language": "python",
+ "metadata": {},
+ "outputs": []
+ }
+ ],
+ "metadata": {}
+ }
+ ]
+}
\ No newline at end of file |