diff options
author | Thomas Stephen Lee | 2015-09-04 22:04:10 +0530 |
---|---|---|
committer | Thomas Stephen Lee | 2015-09-04 22:04:10 +0530 |
commit | 41f1f72e9502f5c3de6ca16b303803dfcf1df594 (patch) | |
tree | f4bf726a3e3ce5d7d9ee3781cbacfe3116115a2c /C_Programming_for_the_Absolute_Beginner/Chapter3.ipynb | |
parent | 9c9779ba21b9bedde88e1e8216f9e3b4f8650b0e (diff) | |
download | Python-Textbook-Companions-41f1f72e9502f5c3de6ca16b303803dfcf1df594.tar.gz Python-Textbook-Companions-41f1f72e9502f5c3de6ca16b303803dfcf1df594.tar.bz2 Python-Textbook-Companions-41f1f72e9502f5c3de6ca16b303803dfcf1df594.zip |
add/remove/update books
Diffstat (limited to 'C_Programming_for_the_Absolute_Beginner/Chapter3.ipynb')
-rwxr-xr-x | C_Programming_for_the_Absolute_Beginner/Chapter3.ipynb | 499 |
1 files changed, 0 insertions, 499 deletions
diff --git a/C_Programming_for_the_Absolute_Beginner/Chapter3.ipynb b/C_Programming_for_the_Absolute_Beginner/Chapter3.ipynb deleted file mode 100755 index a87e263b..00000000 --- a/C_Programming_for_the_Absolute_Beginner/Chapter3.ipynb +++ /dev/null @@ -1,499 +0,0 @@ -{
- "metadata": {
- "name": "",
- "signature": "sha256:4698a1abef67d23e99c2eb6e9534a43d9d501d3ae6147f6ceb242f76f06f63a5"
- },
- "nbformat": 3,
- "nbformat_minor": 0,
- "worksheets": [
- {
- "cells": [
- {
- "cell_type": "heading",
- "level": 1,
- "metadata": {},
- "source": [
- "Chapter 3 CONDITIONS"
- ]
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example 3.1, Page No. 58"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "print \"\\tAC Control Unit\"\n",
- "print \"1\\tTurn the AC on\"\n",
- "print \"2\\tTurn the AC off\"\n",
- "iResponse=int(raw_input(\"Enter your selection::\"))\n",
- "if iResponse==1:\n",
- " print \"AC is now on\"\n",
- "if iResponse==2:\n",
- " print \"AC is now off\""
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "\tAC Control Unit\n",
- "1\tTurn the AC on\n",
- "2\tTurn the AC off\n"
- ]
- },
- {
- "name": "stdout",
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "Enter your selection::1\n"
- ]
- },
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "AC is now on\n"
- ]
- }
- ],
- "prompt_number": 1
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example 3.2, Page No. 59"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "print \"\\tAC Control Unit\"\n",
- "print \"a\\tTurn the AC on\"\n",
- "print \"b\\tTurn the AC off\"\n",
- "cResponse=raw_input(\"Enter your selection::\")\n",
- "if cResponse=='a':\n",
- " print \"AC is now on\"\n",
- "if cResponse=='b':\n",
- " print \"AC is now off\""
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "\tAC Control Unit\n",
- "a\tTurn the AC on\n",
- "b\tTurn the AC off\n"
- ]
- },
- {
- "name": "stdout",
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "Enter your selection::b\n"
- ]
- },
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "AC is now off\n"
- ]
- }
- ],
- "prompt_number": 3
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example 3.3, Page No. 61"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "fBalance = 100.25\n",
- "print \"\\tATM\"\n",
- "print \"1\\tDeposit Funds\"\n",
- "print \"2\\tWithdraw Funds\"\n",
- "iSelection=int(raw_input(\"Enter Your Selection: \"))\n",
- "if iSelection==1:\n",
- " fTransAmount=int(raw_input(\"Enter fund amount to deposit: \"))\n",
- " print \"Your new Balance is: \", fBalance+fTransAmount\n",
- "if iSelection==2:\n",
- " fTransAmount=int(raw_input(\"Enter fund amount to withdraw: \"))\n",
- " if fTransAmout>fBalance:\n",
- " print \"Insufficient Funds\"\n",
- " else:\n",
- " print \"Your new balance is \", fBalance-fTransAmount"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "\tATM\n",
- "1\tDeposit Funds\n",
- "2\tWithdraw Funds\n"
- ]
- },
- {
- "name": "stdout",
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "Enter Your Selection: 1\n"
- ]
- },
- {
- "name": "stdout",
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "Enter fund amount to deposit: 200\n"
- ]
- },
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "Your new Balance is: 300.25\n"
- ]
- }
- ],
- "prompt_number": 4
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example 3.4, Page No. 67"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "cResponse=raw_input(\"Enter a letter A: \")\n",
- "if cResponse=='A':\n",
- " print \"Correct response\"\n",
- "else:\n",
- " print \"Incorrect response\""
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "name": "stdout",
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "Enter a letter A: a\n"
- ]
- },
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "Incorrect response\n"
- ]
- }
- ],
- "prompt_number": 5
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example 3.5, Page No.69"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "iResponse=int(raw_input(\"Enter a numeer from 1 to 10: \"))\n",
- "if iResponse<1 or iResponse>10:\n",
- " print \"Number not in Range\"\n",
- "else:\n",
- " print \"Thank You\""
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "name": "stdout",
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "Enter a numeer from 1 to 10: 5\n"
- ]
- },
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "Thank You\n"
- ]
- }
- ],
- "prompt_number": 3
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example 3.6, Page No. 70"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "cResponse=raw_input(\"Please Enter a letter: \")\n",
- "if not cResponse.isdigit():\n",
- " print \"Thank You\"\n",
- "else:\n",
- " print \"You did not enter a letter\""
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "name": "stdout",
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "Please Enter a letter: 5\n"
- ]
- },
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "You did not enter a letter\n"
- ]
- }
- ],
- "prompt_number": 8
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example 3.7, Page No. 70"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "cResponse=raw_input(\"Please Enter a letter: \")\n",
- "if cResponse.isdigit():\n",
- " print \"Thank You\"\n",
- "else:\n",
- " print \"You did not enter a digit\""
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "name": "stdout",
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "Please Enter a letter: a\n"
- ]
- },
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "You did not enter a digit\n"
- ]
- }
- ],
- "prompt_number": 9
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example 3.8, Page No.72"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "print \"1\\tSports\"\n",
- "print \"2\\tGeography\"\n",
- "print \"3\\tMusic\"\n",
- "print \"4\\tWorld Events\"\n",
- "iResponse=int(raw_input(\"Please select a category (1-4): \"))\n",
- "if iResponse==1:\n",
- " print \"You selected sports questions\"\n",
- "elif iResponse==2:\n",
- " print \"You selected geography questions\"\n",
- "elif iResponse==3:\n",
- " print \"You selected Music questions\"\n",
- "elif iResponse==4:\n",
- " print \"You selected World event questions\""
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "1\tSports\n",
- "2\tGeography\n",
- "3\tMusic\n",
- "4\tWorld Events\n"
- ]
- },
- {
- "name": "stdout",
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "Please select a category (1-4): 4\n"
- ]
- },
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "You selected World event questions\n"
- ]
- }
- ],
- "prompt_number": 1
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example 3.9, Page No. 75"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "import random\n",
- "iRandomNum=(random.randint(0,100)%10)+1\n",
- "iResponse=int(raw_input(\"Guess a number between 1 and 10: \"))\n",
- "if iResponse==iRandomNum:\n",
- " print \"You guessed right\"\n",
- "else:\n",
- " print \"Sorry, you guess wrong\"\n",
- " print \"The correct guess was \",iRandomNum"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "name": "stdout",
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "Guess a number between 1 and 10: 2\n"
- ]
- },
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "Sorry, you guess wrong\n",
- "The correct guess was 3\n"
- ]
- }
- ],
- "prompt_number": 6
- },
- {
- "cell_type": "heading",
- "level": 2,
- "metadata": {},
- "source": [
- "Example 3.10, Page No. 77"
- ]
- },
- {
- "cell_type": "code",
- "collapsed": false,
- "input": [
- "import random\n",
- "iRandomNum=(random.randint(0,100)%4)+1\n",
- "print \"Fortune Cookie - Chapter 3\"\n",
- "if iRandomNum==1:\n",
- " print \"You will meet a new friend\"\n",
- "elif iRandomNum==2:\n",
- " print \"You will enjoy a long and happy life\"\n",
- "elif iRandomNum==3:\n",
- " print \"Opportunity knocks softly. Can you hear it?\"\n",
- "elif iRandomNum==4:\n",
- " print \"You'll be financially rewarded for your good deeds\"\n",
- "\n",
- "print \"Lucky lotto numbers\"\n",
- "print (random.randint(0,100)%49+1)\n",
- "print (random.randint(0,100)%49+1)\n",
- "print (random.randint(0,100)%49+1)\n",
- "print (random.randint(0,100)%49+1)\n",
- "print (random.randint(0,100)%49+1)\n",
- "print (random.randint(0,100)%49+1)"
- ],
- "language": "python",
- "metadata": {},
- "outputs": [
- {
- "output_type": "stream",
- "stream": "stdout",
- "text": [
- "Fortune Cookie - Chapter 3\n",
- "You will enjoy a long and happy life\n",
- "Lucky lotto numbers\n",
- "45\n",
- "17\n",
- "9\n",
- "23\n",
- "2\n",
- "15\n"
- ]
- }
- ],
- "prompt_number": 13
- }
- ],
- "metadata": {}
- }
- ]
-}
\ No newline at end of file |