diff options
Diffstat (limited to 'C++_By_Example/Chapter5.ipynb')
-rwxr-xr-x | C++_By_Example/Chapter5.ipynb | 192 |
1 files changed, 192 insertions, 0 deletions
diff --git a/C++_By_Example/Chapter5.ipynb b/C++_By_Example/Chapter5.ipynb new file mode 100755 index 00000000..44587653 --- /dev/null +++ b/C++_By_Example/Chapter5.ipynb @@ -0,0 +1,192 @@ +{ + "metadata": { + "name": "", + "signature": "sha256:a075bb47fc03df6e4814e3968f8a8dcc720530083267bfa7a0c1a0cea5145710" + }, + "nbformat": 3, + "nbformat_minor": 0, + "worksheets": [ + { + "cells": [ + { + "cell_type": "heading", + "level": 1, + "metadata": {}, + "source": [ + "Chapter5, Character Input/Output and String Functions" + ] + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "C22INI, Page number:452" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Get input\n", + "print \"What is your first initial?\"\n", + "initial=raw_input()\n", + "\n", + "#Check if it is an alphabet\n", + "while not initial.isalpha():\n", + " print \"That was not a valid initial!\"\n", + " print \"What is your first initial?\"\n", + " initial=raw_input()\n", + "print \"Thanks\"\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "What is your first initial?\n" + ] + }, + { + "name": "stdout", + "output_type": "stream", + "stream": "stdout", + "text": [ + "p\n" + ] + }, + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Thanks\n" + ] + } + ], + "prompt_number": 1 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "C22GB, Page number:454" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Get input\n", + "#ans=raw_input(\"Are you a girl or a boy (G/B)? \") \n", + "ans=\"b\"\n", + "\n", + "#convert answer to uppercase\n", + "ans=ans.upper() \n", + "\n", + "if ans=='G':\n", + " print \"You look pretty today!\\n\"\n", + "else:\n", + " if ans=='B':\n", + " print \"You look handsome today!\\n\"\n", + " else:\n", + " print \"Your answer makes no sense!\\n\"\n" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "You look handsome today!\n", + "\n" + ] + } + ], + "prompt_number": 2 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "C22GPS1, Page number:459" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#get book title\n", + "#book=raw_input(\"What is the book title? \") \n", + "book=\"Mary and Her Lambs\"\n", + "\n", + "#print book title\n", + "print book \n", + "\n", + "print \"Thanks for the book!\\n\"" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "Mary and Her Lambs\n", + "Thanks for the book!\n", + "\n" + ] + } + ], + "prompt_number": 3 + }, + { + "cell_type": "heading", + "level": 2, + "metadata": {}, + "source": [ + "C22ABS, Page number:463" + ] + }, + { + "cell_type": "code", + "collapsed": false, + "input": [ + "#Get input\n", + "#age1=input(\"\\nWhat is the first child's age? \")\n", + "#age2=input(\"\\nWhat is the second child's age? \")\n", + "\n", + "age1=10\n", + "age2=12\n", + "\n", + "diff=age1-age2 \n", + "\n", + "# abs() function determines absolute value\n", + "diff=abs(diff) \n", + "\n", + "#Result\n", + "print \"\\nThey are \",diff,\" years apart.\"" + ], + "language": "python", + "metadata": {}, + "outputs": [ + { + "output_type": "stream", + "stream": "stdout", + "text": [ + "\n", + "They are 2 years apart.\n" + ] + } + ], + "prompt_number": 4 + } + ], + "metadata": {} + } + ] +}
\ No newline at end of file |