{ "metadata": { "name": "", "signature": "sha256:2fa8b19d5030cf6dee0c92c2ee4889d5f3659cfd258460db8d8dc9ca2e443363" }, "nbformat": 3, "nbformat_minor": 0, "worksheets": [ { "cells": [ { "cell_type": "code", "collapsed": false, "input": [ "\n", "print \"Hello, World!\\n\"\n" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [ "Hello, World!\n", "\n" ] } ], "prompt_number": 1 }, { "cell_type": "code", "collapsed": false, "input": [ "\n", "\n", "# prints \"Hello, World!\":\n", "print \"Hello, World!\\n\"" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [ "Hello, World!\n", "\n" ] } ], "prompt_number": 2 }, { "cell_type": "code", "collapsed": false, "input": [ "\n", "\n", "# prints \"Hello, World!\":\n", "print \"Hel\" + \"lo, Wo\" + \"rld!\" \n", "\n" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [ "Hello, World!\n" ] } ], "prompt_number": 3 }, { "cell_type": "code", "collapsed": false, "input": [ "\n", "\n", "# prints \"Hello, World!\":\n", "print \"Hello, W\" + 'o' + \"rld\" + '!' " ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [ "Hello, World!\n" ] } ], "prompt_number": 4 }, { "cell_type": "code", "collapsed": false, "input": [ "\n", "\n", "# prints \"The Millennium ends Dec 31 2000.\":\n", "print \"The Millennium ends Dec %d %d \" %(31,2000)" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [ "The Millennium ends Dec 31 2000 \n" ] } ], "prompt_number": 5 }, { "cell_type": "code", "collapsed": false, "input": [ "\n", "# prints \"m = 44 and n = 77\":\n", "\n", "m = 44 # assigns the value 44 to the variable m\n", "print \"m = %d \" % m,\n", "n = m + 33 # assigns the value 77 to the variable n\n", "print \"and n = %d \" % n" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [ "m = 44 and n = 77 \n" ] } ], "prompt_number": 6 }, { "cell_type": "code", "collapsed": false, "input": [ "\n", "\n", "# prints \"n = 44:\n", "n=44\n", "print \"n = %d\" % n" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [ "n = 44\n" ] } ], "prompt_number": 7 }, { "cell_type": "code", "collapsed": false, "input": [ "\n", "\n", "# Python does not have semicolons so wont give any errors.\n", "n=44\n", "print \"n = %d\" % n " ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [ "n = 44\n" ] } ], "prompt_number": 8 }, { "cell_type": "code", "collapsed": false, "input": [ "\n", "\n", "# prints \"m = ?? and n = 44\":\n", "m = 0 #In python we do not have declaration of variables, we just initialize it and use it.\n", "n=44\n", "print \"m = %d and n = %d\" %(m,n)" ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [ "m = 0 and n = 44\n" ] } ], "prompt_number": 9 }, { "cell_type": "code", "collapsed": false, "input": [ "\n", "\n", "# defines constants; has no output:\n", "BEEP = '\\b'\n", "MAXINT = 2147483647\n", "N = MAXINT/2\n", "KM_PER_MI = 1.60934\n", "PI = 3.14159265358979323846\n" ], "language": "python", "metadata": {}, "outputs": [], "prompt_number": 10 }, { "cell_type": "code", "collapsed": false, "input": [ "\n", "\n", "# tests the input of integers, floats, and characters:\n", "print \"Enter two integers: \"\n", "m = int(raw_input())\n", "n = int(raw_input())\n", "print \"m = %d , n = %d \" %(m,n)\n", "\n", "print \"Enter three decimal numbers: \"\n", "x = float(raw_input())\n", "y = float(raw_input())\n", "z = float(raw_input())\n", "\n", "print \"x = %f , y = %f , z = %f\" %(x,y,z)\n", "\n", "print \"Enter four characters: \";\n", "c1 = raw_input()\n", "c2 = raw_input()\n", "c3 = raw_input()\n", "c4 = raw_input()\n", "print \"c1 = \" + c1 + \", c2 = \" + c2 + \", c3 = \" + c3 + \", c4 = \" + c4 " ], "language": "python", "metadata": {}, "outputs": [ { "output_type": "stream", "stream": "stdout", "text": [ "Enter two integers: \n" ] }, { "name": "stdout", "output_type": "stream", "stream": "stdout", "text": [ "22\n" ] }, { "name": "stdout", "output_type": "stream", "stream": "stdout", "text": [ "44\n" ] }, { "output_type": "stream", "stream": "stdout", "text": [ "m = 22 , n = 44 \n", "Enter three decimal numbers: \n" ] }, { "name": "stdout", "output_type": "stream", "stream": "stdout", "text": [ "2.2\n" ] }, { "name": "stdout", "output_type": "stream", "stream": "stdout", "text": [ "4.4\n" ] }, { "name": "stdout", "output_type": "stream", "stream": "stdout", "text": [ "6.6\n" ] }, { "output_type": "stream", "stream": "stdout", "text": [ "x = 2.200000 , y = 4.400000 , z = 6.600000\n", "Enter four characters: \n" ] }, { "name": "stdout", "output_type": "stream", "stream": "stdout", "text": [ "A\n" ] }, { "name": "stdout", "output_type": "stream", "stream": "stdout", "text": [ "B\n" ] }, { "name": "stdout", "output_type": "stream", "stream": "stdout", "text": [ "C\n" ] }, { "name": "stdout", "output_type": "stream", "stream": "stdout", "text": [ "D\n" ] }, { "output_type": "stream", "stream": "stdout", "text": [ "c1 = A, c2 = B, c3 = C, c4 = D\n" ] } ], "prompt_number": 11 }, { "cell_type": "code", "collapsed": false, "input": [], "language": "python", "metadata": {}, "outputs": [] } ], "metadata": {} } ] }