# HG changeset patch # User Puneeth Chaganti # Date 1290016497 -19800 # Node ID 88a01948450d1107f3144fc1652ab0171ce7dbf3 # Parent 8249ae9d570ad31157c8183bac23244bf5ec2e5c# Parent 70faad10e8540a0dfe6b099e0e6b6f9c36762d91 Merged heads. diff -r 8249ae9d570a -r 88a01948450d additional_ipython/script.rst --- a/additional_ipython/script.rst Wed Nov 17 23:24:23 2010 +0530 +++ b/additional_ipython/script.rst Wed Nov 17 23:24:57 2010 +0530 @@ -15,9 +15,10 @@ .. 1. Embellishing Plots .. Author : Nishanth Amuluru - Internal Reviewer : + Internal Reviewer : Amit External Reviewer : - Checklist OK? : [2010-10-05] + Language Reviewer : Bhanukiran + Checklist OK? : <15-11-2010, Anand, OK> [2010-10-05] Script ------ diff -r 8249ae9d570a -r 88a01948450d dictionaries/script.rst --- a/dictionaries/script.rst Wed Nov 17 23:24:23 2010 +0530 +++ b/dictionaries/script.rst Wed Nov 17 23:24:57 2010 +0530 @@ -20,7 +20,8 @@ .. Author : Anoop Jacob Thomas Internal Reviewer : Puneeth External Reviewer : - Checklist OK? : [2010-10-05] + Language Reviewer : Bhanukiran + Checklist OK? : <11-11-2010, Anand, OK> [2010-10-05] .. #[Puneeth: Quickref] @@ -139,8 +140,8 @@ extensions['cpp'] = 'C++ source code' extensions -As you can see, it did not add a new thing nor gave an error, but it -simply replaces the existing value with the new one. +As you can see, it neither added a new thing nor gave an error, but it +simply replaced the existing value with the new one. Now let us learn how to check if a particular key is present in the dictionary. For that we can use ``in``, diff -r 8249ae9d570a -r 88a01948450d embellishing_a_plot/script.rst --- a/embellishing_a_plot/script.rst Wed Nov 17 23:24:23 2010 +0530 +++ b/embellishing_a_plot/script.rst Wed Nov 17 23:24:57 2010 +0530 @@ -16,9 +16,10 @@ .. 1. Using the ``plot`` command interactively .. Author : Nishanth Amuluru - Internal Reviewer : + Internal Reviewer : Anoop External Reviewer : - Checklist OK? : [2010-10-05] + Language Reviewe : Bhanukiran + Checklist OK? : <15-11-2010, Anand, OK> [2010-10-05] Script ------ @@ -30,9 +31,9 @@ {{{ Show the slide containing the outline }}} In this tutorial, we shall look at how to modify the colour, thickness and -linestyle of the plot. We shall then learn how to add title to the plot and +linestyle of a plot. We shall then learn how to add title to a plot and then look at adding labels to x and y axes. we shall also look at adding -annotations to the plot and setting the limits of axes. +annotations to the plot and setting the limits on the axes. Let us start ipython with pylab loaded, by typing on the terminal @@ -59,14 +60,13 @@ points right?] As we can see, the default colour and the default thickness of the -line is as decided by pylab. Wouldn't be nice if we could control +line is as decided by pylab. Wouldn't it be nice if we could control these parameters in the plot? This is possible by passing additional arguments to the plot command. .. #[[Anoop: I think it will be good to rephrase the sentence]] .. #[madhu: Why "you" here? Shouldn't this be "we" as decided? Also I added "the default" check the diff] - The additional argument that we shall be passing in here now is the colour argument. We shall first clear the figure and plot the same in red colour. Hence @@ -243,7 +243,9 @@ The solution is to enclose the whole string in between $. Hence, :: - title("$Parabolic function -x^2+4x-5$") + title("Parabolic function $-x^2+4x-5$") +#[[Bhanu: Dollar sign should enclose only the math-expression. change +made.]] gives a title that looks neatly formatted. diff -r 8249ae9d570a -r 88a01948450d getting-started-sagenotebook/script.rst --- a/getting-started-sagenotebook/script.rst Wed Nov 17 23:24:23 2010 +0530 +++ b/getting-started-sagenotebook/script.rst Wed Nov 17 23:24:57 2010 +0530 @@ -22,9 +22,10 @@ .. None. .. Author : Madhu - Internal Reviewer : + Internal Reviewer : Punch External Reviewer : - Checklist OK? : [2010-10-05] + Language Reviewer : Bhanukiran + Checklist OK? : <15-11-2010, Anand, OK> [2010-10-05] Script @@ -46,8 +47,8 @@ {{{ Show the slide on what is Sage }}} To start with, What is Sage? Sage is a free, open-source mathematical -software. Sage can do a lot of math stuff for you including but not -limited to algebra, calculus, geometry, cryptography, graph theory +software. Sage can do a lot of math stuff for you including, but not +limited to, algebra, calculus, geometry, cryptography, graph theory among other things. It can also be used as aid in teaching and research in any of the areas that Sage supports. So let us start Sage now @@ -70,10 +71,10 @@ {{{ Show what is displayed on the terminal }}} So now we can type all the commands that Sage supports here. But Sage -comes bundled with a much much much more elegant tool called Sage +comes bundled with a much more elegant tool called Sage Notebook? What is Sage Notebook? Sage Notebook provides a web based user interface to use Sage. So once we have a Sage notebook server up -and running all we want is a browser to access the Sage +and running, all we want is a browser to access the Sage functionality. For example there is an official instance of Sage Notebook server running at http://sagenb.org You can visit that page, create an account there and start using Sage! So all you need is just @@ -81,6 +82,8 @@ {{{ Intentional *cough* *cough* }}} +#[[Bhanu: what? Are you serious?]] + to use Sage and nothing else! The Sage notebook also provides a convenient way of sharing and publishing our work, which is very handy for research and teaching. @@ -120,7 +123,7 @@ Once we are logged in with the admin account we can see the notebook admin page. A notebook can contain a collection of Sage Notebook -worksheets. Worksheets are basically the working area. This is where +worksheets. Worksheet is basically a working area. This is where we enter all the Sage commands on the notebook. The admin page lists all the worksheets created. On the topmost part @@ -132,8 +135,8 @@ The home link takes us to the admin home page. The published link takes us to the page which lists all the published worksheets. The log link has the complete log of all the actions we did on the -notebook. We have the settings link where can configure our notebook, -the notebook server, we can create and mangage accounts. We have a +notebook. We have the settings link where we can configure our notebook, +the notebook server, create and mangage accounts. We have a link to help upon clicking opens a new window with the complete help of Sage. The entire documentation of Sage is supplied with Sage for offline reference and this help link is the way to get into it. Then diff -r 8249ae9d570a -r 88a01948450d getting-started-strings/script.rst --- a/getting-started-strings/script.rst Wed Nov 17 23:24:23 2010 +0530 +++ b/getting-started-strings/script.rst Wed Nov 17 23:24:57 2010 +0530 @@ -16,9 +16,10 @@ .. 1. getting started with ipython .. Author : Madhu - Internal Reviewer : + Internal Reviewer : Punch External Reviewer : - Checklist OK? : [2010-10-05] + Language Reviewer : Bhanukiran + Checklist OK? : <15-11-2010, Anand, OK> [2010-10-05] Script ------ @@ -31,7 +32,7 @@ {{{ Show the slide containing the outline }}} In this tutorial, we will look at what we really mean by strings, how -python supports the use of strings and some of the operations that can +Python supports the use of strings and some of the operations that can be performed on strings. {{{ Shift to terminal and start ipython }}} @@ -162,9 +163,9 @@ a = 'hello' a[0] = 'H' -As said earlier, strings are immutable. We cannot manipulate the -string. Although there are some methods which let us to manipulate the -strings. We will look at them in the advanced session on strings. In +As said earlier, strings are immutable. We cannot manipulate a +string. Although there are some methods which let us manipulate +strings, we will look at them in the advanced session on strings. In addition to the methods that let us manipulate the strings we have methods like split which lets us break the string on the specified separator, the join method which lets us combine the list of strings diff -r 8249ae9d570a -r 88a01948450d getting-started-with-arrays/script.rst --- a/getting-started-with-arrays/script.rst Wed Nov 17 23:24:23 2010 +0530 +++ b/getting-started-with-arrays/script.rst Wed Nov 17 23:24:57 2010 +0530 @@ -20,7 +20,8 @@ .. Author: Anoop Jacob Thomas Internal Reviewer : Puneeth External Reviewer : - Checklist OK? : [2010-10-05] + Language Reviewer : Bhanukiran + Checklist OK? : <11-11-2010,Anand, OK > [2010-10-05] =========================== Getting started with Arrays @@ -34,17 +35,17 @@ {{{ switch to next slide, outline slide }}} -In this tutorial, we will learn about arrays, we will learn how to convert -a list into an array array operations and also why an array is preferred -over lists. +In this tutorial, we will learn about the data structure called an array, how to convert +a list into an array, operations on arrays and also why an array is preferred +to lists. .. #[Puneeth: Fix the grammar above.] {{{ switch to next slide on overview of array }}} Arrays are homogeneous data structures. Unlike lists, arrays cannot have -heterogeneous data elements, that is, it can have only one type of data -type, either all integers, or strings, or float, and not a mix. +heterogeneous data elements, that is, they can have only one type of data +as their entries, be them all integers, strings, or maybe floats, but not a mix. .. #[Puneeth: Use multiple short sentences, rather than one long sentence I would've written something like this. @@ -52,8 +53,9 @@ Unlike lists, arrays are homogeneous data structures. They can have only type of data, ....] -Arrays are really fast in mathematical operations when compared to lists, -because of the same type of data in arrays. +Arrays of a given length are comparatively much faster in mathematical +operations than lists of the same length, because of the fact that they are +homogeneous data structures. .. #[Puneeth: For what size of an array is that the comparison? @@ -77,7 +79,7 @@ a1 = array([1,2,3,4]) -Notice that here we created a one dimensional array. Also notice the object +Notice that we created a one dimensional array here. Also notice the object we passed to create an array. We passed a list to create an array. Now let us see how to create a two dimensional array. Pause here and try to @@ -112,7 +114,7 @@ .. #[Puneeth: say, creating the same array as before. for some time I got .. confused .] -And we obtained a single dimensional array with elements from 1 to 8. +And we obtained a one dimensional array with elements from 1 to 8. :: @@ -120,7 +122,7 @@ .. #[Puneeth: be consistent with voice. say, we obtained... or something.] -And how can we make it a two dimensional array of order 2 by 4. Pause here +And how can we make it a two dimensional array of order 2 by 4? Pause here and try to do it yourself, try ``ar.tab`` and find a suitable method for that. @@ -154,13 +156,13 @@ {{{ switch to the next slide, problem statement of unsolved exercise 1 }}} -Create a three dimensional array of the order (2,2,4). +Create a three dimensional array of the shape (2,2,4). .. #[Puneeth: s/order/shape or size ?] {{{ switch to the next slide, shape of an array }}} -To find the shape of an array we can use the object ``.shape``, let us +To find the shape of an array we can use the method ``.shape``, let us check the shape of the arrays we have created so far, .. #[Puneeth: s/object/method ?] @@ -200,8 +202,8 @@ a4 = array([1,2,3,'a string']) -Well, we expected an error as previously I said that an array can have only -homogeneous elements, but it didn't give an error. Let us check the values +Well, we would expect an error as it has been previously mentioned that arrays handle +elements with the same datatype, but it didn't raise an error. Let us check the values in the new array created. In your IPython terminal type, :: @@ -218,8 +220,8 @@ {{{ highlight all the array elements one by one using mouse movements }}} -all the elements have been implicitly type casted as string, though our -first three elements were integers. +all the elements have been implicitly type casted as strings, though our +first three elements were meant to be integers. .. #[Puneeth: when I type a4 it says some ``dtype`` etc. I don't understand .. what it is, can you explain? ;)] @@ -229,25 +231,26 @@ .. #[Puneeth: something needs to motivate this. why are we suddenly talking .. of an identity matrix?] -Now let us see how to create identity matrix, an identity matrix is a -square matrix in which all the diagonal elements are one and rest of the -elements zero. We can create an identity matrix using the method +Now let us see how to create an identity matrix of a given size, that is a +two-dimensional array in which all the diagonal elements are ones and rest of the +elements are zeros. We can create an identity matrix using the function ``identity()``. -The function ``identity()`` takes an integer argument, +The function ``identity()`` takes an integer argument which specifies the +size of the desired matrix, :: identity(3) -As you can see the identity method returned a three by three square matrix -with all the diagonal elements as one and the rest of the elements as zero. +As you can see the identity function returned a three by three square matrix +with all the diagonal elements as ones and the rest of the elements as zeros. .. #[Puneeth: You say array here, matrix there -- it's a bit messed up. .. Clarify, explicitly.] -``zeros()`` function accepts a tuple, which is the order of the array we -want to create, and it generates an array with all elements zero. +``zeros()`` function accepts a tuple, which is the order of the array that we +want to create, and it generates an array with all elements as zeros. {{{ switch to the next slide, problem statement of solved exercise 1 }}} diff -r 8249ae9d570a -r 88a01948450d getting-started-with-for/script.rst --- a/getting-started-with-for/script.rst Wed Nov 17 23:24:23 2010 +0530 +++ b/getting-started-with-for/script.rst Wed Nov 17 23:24:57 2010 +0530 @@ -22,7 +22,8 @@ Internal Reviewer : Nishanth Internal Reviewer(2): Amit External Reviewer : - Checklist OK? : [2010-10-05] + Language Reviewer : Bhanukiran + Checklist OK? : <10-11-2010, Anand, OK> [2010-10-05] ============================= @@ -31,7 +32,7 @@ {{{ show welcome slide }}} -Hello and welcome to the tutorial getting started with ``for`` loop. +Hello and welcome to the tutorial `Getting started with ``for`` loop`. {{{ switch to next slide, outline slide }}} @@ -156,7 +157,7 @@ it means that it is not part of the ``for`` loop and the lines after that doesn't fall in the scope of the ``for`` loop. Thus each block is -separated by the indentation level. Thus marking the importance of +separated by the indentation level and that marks the importance of white-spaces in Python. {{{ switch to the slide which shows the problem statement of the first @@ -204,8 +205,8 @@ print "is", sqrt(each) Now we have finished the statements in the block, and still the -interpreter is showing four dots, which means you are still inside the -block. To exit from the block press return key or the enter key twice +interpreter is showing four dots, this means that you are still inside the +block. To exit from the block press the return key or the enter key twice without entering anything else. It printed the square root of each number in the list, and that is executed in a ``for`` loop. @@ -252,7 +253,7 @@ {{{ switch to the next slide, ``range()`` function }}} -Okay! so the main thing here we learned is how to use Python +Okay! so the main thing that we learned here is how to use Python interpreter and IPython interpreter to specify blocks. But while we were generating the multiplication table we used something new, ``range()`` function. ``range()`` is an inbuilt function in Python diff -r 8249ae9d570a -r 88a01948450d getting-started-with-functions/script.rst --- a/getting-started-with-functions/script.rst Wed Nov 17 23:24:23 2010 +0530 +++ b/getting-started-with-functions/script.rst Wed Nov 17 23:24:57 2010 +0530 @@ -23,7 +23,8 @@ .. Author : Anoop Jacob Thomas Internal Reviewer : External Reviewer : - Checklist OK? : [2010-10-05] + Language Reviewer : Bhanukiran + Checklist OK? : [2010-10-05] ============================== @@ -32,29 +33,29 @@ {{{ show welcome slide }}} -Hello and welcome to the tutorial, getting started with functions. +Hello and welcome to the tutorial getting started with functions. {{{ switch to next slide, outline slide }}} In this tutorial we will learn about functions in python, how to -define functions, passing arguments to functions, docstrings, and -function return value. +define functions, arguments to functions, docstrings, and function +return value. {{{ switch to next slide, Function }}} -While writing code, we would like to reduce the number of lines of -code and using functions is a way of reusing the code. A function is -a portion of code within a larger program that performs a specific -task and is relatively independent of the remaining code. Now let us -get more familiar with functions, +While writing code, we always want to reduce the number of lines of +code and functions is a way of reusing the code. Thus the same lines +of code can be used as many times as needed. A function is a portion of code +within a larger program that performs a specific task and is +relatively independent of the remaining code. Now let us get more +familiar with functions, {{{ switch to next slide, f(x) a mathematical function }}} -Consider a mathematical function f(x) = x squared. Here x is a -variable and with different values of x the value of function will -change. When x is one f(1) will return the value 1 and f(2) will -return us the value 4. Let us now see how to define the function f(x) -in Python. +Consider a mathematical function f(x) = x square. Here x is a variable +and with different values of x the value of function will change. When +x is one f(1) will return the value 1 and f(2) will return us the +value 4. Let us now see how to define the function f(x) in python. {{{ switch to next slide, define f(x) in Python }}} @@ -64,22 +65,19 @@ def f(x): return x*x -Let us see, if the function ``f``, we defined, works as we expect. +Well that defined the function, so before learning what we did let us +see if it returns the expected values, try, :: f(1) f(2) -Yes, it returned 1 and 2 respectively. - -Now, let us see what we did. The first line ``def f(x)`` is used to -define the name and the parameters to the function. ``def`` is a -keyword and ``f`` is the name of the function and ``x`` the parameter -of the function. - -The second line is the body of the function. Incidentally, this -function has a single line definition. Note that the body of the -function is indented, just like any other code block, in Python. +Yes, it returned 1 and 4 respectively. And now let us see what we did. +We wrote two lines: The first line ``def f(x)`` is used to define the +name and the parameters to the function and the second line is used to +fix what the function is supposed to return. ``def`` is a keyword and +``f`` is the name of the function and ``x`` the parameter of the +function. {{{ switch to next slide, problem statement 1 }}} @@ -96,18 +94,18 @@ def cube(n): return n**3 -Now let us see how to write functions without arguments. +And now let us see how to write functions without arguments. {{{ switch to next slide, greet function }}} -Let us define a new function called ``greet`` which will print ``Hello +let us define a new function called ``greet`` which will print ``Hello World``. :: def greet(): print "Hello World!" -Now try calling the function, +now try calling the function, :: greet() @@ -127,22 +125,22 @@ {{{ switch to next slide, solution 2 }}} -The problem can be solved as shown, +The problem can be solved as, :: def avg(a,b): return (a + b)/2 Thus if we want a function to accept more arguments, we just list them -separated with a comma between the parenthesis after the function name +separated with a comma between the parenthesis after the function's name in the ``def`` line. {{{ switch to next slide, docstring }}} It is always a good practice to document the code that we write, and for a function we define we should write an abstract of what the -function does, and that is called a doc-string. Let us modify the -function ``avg`` and add doc-string to it. Do the following, +function does, and that is called a docstring. Let us modify the +function ``avg`` and add docstring to it. Do the following, :: def avg(a,b): @@ -150,7 +148,7 @@ returns the average of a and b""" return (a+b)/2 -Note that doc-strings are entered in the immediate line after the +Note that docstrings are entered in the immediate line after the function definition and put as a triple quoted string. And here as far as the code functionality is concerned, we didn't do anything. We just added an abstract of what the function does. @@ -170,7 +168,7 @@ It doesn't have a docstring associated with it. Also we cannot infer anything from the function name, and thus we are forced to read the -code to understand anything about the function. +code to understand about the function. {{{ switch to next slide, exercise 3 }}} @@ -238,8 +236,8 @@ {{{ switch to next slide, even_digits }}} .. def even_digits( n ): -.. """returns True if all the digits of number n is even -.. returns False if all the digits of number n is not even""" +.. """returns True if all the digits in the number n are even, +.. returns False if all the digits in the number n are not even""" .. if n < 0: n = -n .. while n > 0: .. if n % 2 == 1: @@ -290,9 +288,6 @@ We also did few code reading exercises. -{{{ Show the "sponsored by FOSSEE" slide }}} +{{{ switch to next slide, Thank you }}} -This tutorial was created as a part of FOSSEE project, NME ICT, MHRD India - -Hope you have enjoyed and found it useful. Thank you! diff -r 8249ae9d570a -r 88a01948450d getting-started-with-lists/script.rst --- a/getting-started-with-lists/script.rst Wed Nov 17 23:24:23 2010 +0530 +++ b/getting-started-with-lists/script.rst Wed Nov 17 23:24:57 2010 +0530 @@ -22,7 +22,8 @@ .. Author : Amit Internal Reviewer : Anoop Jacob Thomas External Reviewer : - Checklist OK? : [2010-10-05] + Language Reviewer : Bhanukiran + Checklist OK? : <12-11-2010, Anand, OK> [2010-10-05] .. #[[Anoop: Slides contain only outline and summary @@ -44,9 +45,9 @@ * Append elements to lists * Delete elements from lists -List is a compound data type, it can contain data of other data -types. List is also a sequence data type, all the elements are in -order and the order has a meaning. +List is a compound data type, it can contain data of mutually +different datatypes. List is also a sequence data type, all the +elements are arranged in a given order. .. #[[Anoop: "all the elements are in order and **there** order has a meaning." - I guess something is wrong here, I am not able to @@ -69,13 +70,13 @@ nonempty = ['spam', 'eggs', 100, 1.234] Thus the simplest way of creating a list is typing out a sequence -of comma-separated values (items) between square brackets. -All the list items need not be of the same data type. +of comma-separated values (or items) between two square brackets. As we can see lists can contain different kinds of data. In the -previous example 'spam' and 'eggs' are strings and 100 and 1.234 are -integer and float. Thus we can put elements of heterogenous types in -lists including list itself. +previous example 'spam' and 'eggs' are strings whereas 100 and 1.234 are +integer and float respectively. Thus we can put elements of different types in +lists including lists itself. This property makes lists heterogeneous +data structures. .. #[[Anoop: the sentence "Thus list themselves can be one of the element types possible in lists" is not clear, rephrase it.]] @@ -84,9 +85,10 @@ listinlist=[[4,2,3,4],'and', 1, 2, 3, 4] -We access list elements using the index. The index begins from 0. So -for list nonempty, nonempty[0] gives the first element, nonempty[1] -the second element and so on and nonempty[3] the last element. :: +We access an element of a list using its corresponding index. Index of +the first element of a list is 0. So for the list nonempty, nonempty[0] +gives the first element, nonempty[1] the second element and so on and +nonempty[3] the last element. :: nonempty[0] nonempty[1] @@ -112,9 +114,9 @@ nonempty[-4] -1 gives the last element which is the 4th element , -2 second to last -and -4 gives the fourth from last element which is first element. +and -4 gives the fourth from the last which, in this case, is the first element. -We can append elements to the end of a list using append command. :: +We can append elements to the end of a list using the method append. :: nonempty.append('onemore') nonempty @@ -134,10 +136,10 @@ The solution is on your screen -As we can see non empty appends 'onemore' and 6 at the end. +As we can see nonempty is appended with 'onemore' and 6 at the end. Using len function we can check the number of elements in the list -nonempty. In this case it 6 :: +nonempty. In this case it is 6 :: len(nonempty) @@ -153,7 +155,7 @@ deletes the element at index 1, i.e the second element of the list, 'eggs'. The other way is removing element by content. Lets say one wishes to delete 100 from nonempty list the syntax of the command -should be +would be .. #[[Anoop: let x = [1,2,1,3] now x.remove(x[2]) @@ -175,9 +177,25 @@ nonempty If we check now we will see that the first occurence 'spam' is removed -thus remove removes the first occurence of the element in the sequence +and therefore `remove` removes the first occurence of the element in the sequence and leaves others untouched. +One should remember this that while del removes by index number, +`remove` removes on the basis of content being passed on. For instance +if :: + + k = [1,2,1,3] + del([k[2]) + +gives us [1,2,3]. :: + + k.remove(x[2]) + +will give us [2,1,3]. Since it deletes the first occurence of what is +returned by x[2] which is 1. + + + diff -r 8249ae9d570a -r 88a01948450d getting-started-with-symbolics/script.rst --- a/getting-started-with-symbolics/script.rst Wed Nov 17 23:24:23 2010 +0530 +++ b/getting-started-with-symbolics/script.rst Wed Nov 17 23:24:57 2010 +0530 @@ -20,7 +20,8 @@ .. Author : Amit Internal Reviewer : External Reviewer : - Checklist OK? : [2010-10-05] + Language Reviewer : Bhanukiran + Checklist OK? : <, if OK> [2010-10-05] Symbolics with Sage ------------------- @@ -40,11 +41,11 @@ * Defining symbolic functions. * Simplifying and solving symbolic expressions and functions. -Amongst a lot of other things, Sage can do Symbolic Math and we shall +In addtion to a lot of other things, Sage can do Symbolic Math and we shall start with defining symbolic expressions in Sage. -Hope you have your Sage notebook open. If not, pause the video and -start you Sage notebook. +Have your Sage notebook opened. If not, pause the video and +start you Sage notebook right now. On the sage notebook type:: @@ -63,7 +64,7 @@ Sage simply returns the expression. Sage treats ``sin(y)`` as a symbolic expression. We can use this to do -symbolic maths using Sage's built-in constants and expressions. +symbolic math using Sage's built-in constants and expressions. Let us try out a few examples. :: @@ -286,7 +287,7 @@ as we can see when we substitute the value the answer is almost = 0 showing the solution we got was correct. -Following is an (are) exercise(s) that you must do. +Following are a few exercises that you must do. %% %% Differentiate the following. diff -r 8249ae9d570a -r 88a01948450d input_output/script.rst --- a/input_output/script.rst Wed Nov 17 23:24:23 2010 +0530 +++ b/input_output/script.rst Wed Nov 17 23:24:57 2010 +0530 @@ -14,7 +14,8 @@ .. Author : Nishanth Amuluru Internal Reviewer : Puneeth External Reviewer : - Checklist OK? : [2010-10-05] + Language Reviewer : Bhanukiran + Checklist OK? : [2010-10-05] Script ------ diff -r 8249ae9d570a -r 88a01948450d lstsq/script.rst --- a/lstsq/script.rst Wed Nov 17 23:24:23 2010 +0530 +++ b/lstsq/script.rst Wed Nov 17 23:24:57 2010 +0530 @@ -11,9 +11,10 @@ .. 3. Loading data from files .. Author : Nishanth Amuluru - Internal Reviewer : + Internal Reviewer : Punch External Reviewer : - Checklist OK? : [2010-10-05] + Language Reviewer : Bhanukiran + Checklist OK? : [2010-10-05] .. #[Puneeth: Add pre-requisites.] diff -r 8249ae9d570a -r 88a01948450d manipulating-lists/script.rst --- a/manipulating-lists/script.rst Wed Nov 17 23:24:23 2010 +0530 +++ b/manipulating-lists/script.rst Wed Nov 17 23:24:57 2010 +0530 @@ -11,9 +11,10 @@ .. 3. .. Author : Madhu - Internal Reviewer : + Internal Reviewer : Punch External Reviewer : - Checklist OK? : [2010-10-05] + Language Reviewer : Bhanukiran + Checklist OK? : <16-11-2010, Anand, OK> [2010-10-05] Script ------ @@ -24,10 +25,10 @@ {{{ Show the slide containing the outline }}} -We have already learnt a lot about Lists in Python. In this tutorial, -we will learn more about advanced features of Lists in Python. We will -see how to concatenate two lists, details of slicing and striding of -lists, methods to sort and reverse lists. +We have already learnt about Lists in Python. In this tutorial, +we will learn about more advanced features of Lists in Python like how +to concatenate two lists, details of slicing and striding of lists, +methods to sort and reverse lists. {{{ Shift to terminal and start ipython }}} @@ -49,16 +50,16 @@ primes = [2, 3, 5, 7, 11, 13, 17, 19, 23, 29] -To obtain the all the primes between 10 and 20 from the above list of +To obtain all the primes between 10 and 20 from the above list of primes we say:: primes[4:8] This gives us all the elements in the list starting from the element -with the index 4 which is 11 in our list upto the element with index 8 +with the index 4, which is 11 in our list, upto the element with index 8 in the list but not including the eigth element. So we obtain a slice starting from 11 upto 19th. It is a very important to remember that -when ever we specify a range of elements in Python the start index is +whenever we specify a range of elements in Python the start index is included and end index is not included. So in the above case, 11 which was the element with the index 4 was included but 23 which was the element with index 8 was excluded. @@ -129,7 +130,7 @@ gives us all the multiples of 3 from the list, since every third element in it, starting from 0, is divisible by 3. -The other basic operation that we can perform on list is concatenation +The other basic operation that we can perform on lists is concatenation of two or more lists. We can combine two lists by using the "plus" operator. Say we have @@ -160,7 +161,7 @@ a [1, 5, 6, 7, 7, 10] -Since the sort method sorts the list inplace the original list we had +As the sort method sorts the elements of a list, the original list we had is overwritten or replaced. We have no way to obtain the original list back. One way to avoid this is to keep a copy of the original list in another variable and run the sort method on the list. However Python @@ -174,8 +175,7 @@ sa = sorted(a) -Similarly to perform certain operations on the list we would like to -reverse the list. Python provides reverse method which again reverses +Python also provides the reverse method which reverses the list inplace:: a = [1, 2, 3, 4, 5] diff -r 8249ae9d570a -r 88a01948450d matrices/script.rst --- a/matrices/script.rst Wed Nov 17 23:24:23 2010 +0530 +++ b/matrices/script.rst Wed Nov 17 23:24:57 2010 +0530 @@ -26,9 +26,10 @@ .. Author : Anoop Jacob Thomas - Internal Reviewer : + Internal Reviewer : Puneeth External Reviewer : - Checklist OK? : [2010-10-05] + Language Reviewer : Bhanukiran + Checklist OK? : <11-11-2010, Anand, OK> [2010-10-05] .. #[punch: please mark the exercises, using the syntax we decided upon.] @@ -42,7 +43,7 @@ {{{ switch to next slide, outline slide }}} In this tutorial we will learn about matrices, creating matrices using -direct data, by converting a list and matrix operations. Finding +direct data, converting a list and matrix operations. Finding inverse of a matrix, determinant of a matrix, eigen values and eigen vectors of a matrix, norm and singular value decomposition of matrices. @@ -59,7 +60,7 @@ .. #[Puneeth: don't use ``matrix``. Use ``array``. The whole script will .. have to be fixed.] -Using the tuple ``m1.shape`` we can find out the shape or size of the +Using the method ``shape`` we can find out the shape or size of the matrix, :: diff -r 8249ae9d570a -r 88a01948450d multiple-plots/script.rst --- a/multiple-plots/script.rst Wed Nov 17 23:24:23 2010 +0530 +++ b/multiple-plots/script.rst Wed Nov 17 23:24:57 2010 +0530 @@ -20,6 +20,9 @@ Internal Reviewer 1 : [potential reviewer: Puneeth] Internal Reviewer 2 : Nishanth External Reviewer : + Language Reviewer : Bhanukiran + Checklist OK? : <, not OK> [] + Script ------ @@ -205,7 +208,7 @@ {{{ Have both plot window and ipython side by side }}} -We also titled the our first plot as 'sin(y)' which we did not do for +We also titled our first plot as 'sin(y)' which we did not do for the second plot. Let us attempt another exercise problem @@ -264,7 +267,7 @@ {{{ Have both plot window and ipython side by side }}} -in this case we have 2 so it spilts the plotting area horizontally for +in this case we have 2 as the first argument so it spilts the plotting area horizontally for two subplots. The second argument specifies the number of coloumns of subplots that must be created. We passed 1 as the argument so the plotting area won't be split vertically and the last argument diff -r 8249ae9d570a -r 88a01948450d other-type-of-plots/script.rst --- a/other-type-of-plots/script.rst Wed Nov 17 23:24:23 2010 +0530 +++ b/other-type-of-plots/script.rst Wed Nov 17 23:24:57 2010 +0530 @@ -20,7 +20,8 @@ .. Author : Anoop Jacob Thomas Internal Reviewer : Puneeth External Reviewer : - Checklist OK? : [2010-10-05] + Language Reviewer : Bhanukiran + Checklist OK? : <10-11-2010, Anand, OK> [2010-10-05] .. #[Puneeth: Quickref missing] @@ -30,7 +31,7 @@ {{{ show the first slide }}} -Hello and welcome to the tutorial other type of plots. +Hello and welcome to the tutorial ``The other kinds of plots``. .. #[Puneeth: this sentence doesn't read well] @@ -40,10 +41,10 @@ .. them? Tell that we have only looked at one type of plot all the .. while, etc.] -Till now we have seen only one type of plot, and in this tutorial us -see more type of plots like scatter plot, pie chart, bar chart and -log-log plot. We will see few other more plots and also see an -introduction to matplotlib help. +Till now we have seen only one kind of plotting, and in this tutorial we +are going to see more kinds of plots such as the scatter plot, the pie chart, the bar chart and +the log-log plot. This tutorial covers the making of other kinds of +plots and also gives an introduction to matplotlib help. .. #[Puneeth: cover, see and introduce you. be consistent. does, the .. "We" include the viewer or not?] @@ -56,7 +57,7 @@ each having the value of one variable determining the position on the horizontal axis and the value of the other variable determining the position on the vertical axis. This kind of plot is also called a -scatter chart, scatter diagram and scatter graph. +scatter chart, a scatter diagram or a scatter graph. Before we proceed further, start your IPython interpreter :: @@ -70,7 +71,7 @@ exercise }}} Now, let us plot a scatter plot showing the percentage profit of -company A from the year 2000-2010. The data for the same is available +a company A from the year 2000-2010. The data for the same is available in the file ``company-a-data.txt``. {{{ open the file company-a-data.txt and show the content }}} @@ -81,7 +82,7 @@ {{{ close the file and switch to the terminal }}} -To produce the scatter plot first we need to load the data from the +To produce the scatter plot, we first need to load the data from the file using ``loadtxt``. We learned it in one of the previous sessions, and it can be done as :: @@ -119,8 +120,7 @@ .. scatter(year,profit,color='r',marker='d') -Now let us see another plot, pie chart and try to plot the same data -as a pie chart. +Now let us see another kind of plot, the pie chart, for the same data. .. #[Puneeth: instead of just saying that, say that let's plot a pie .. chart for the same data. continuity, will be good.] @@ -165,7 +165,7 @@ {{{ switch to the slide which says about bar chart }}} -Now let us move on to bar chart. A bar chart or bar graph is a chart +Now let us move on to the bar charts. A bar chart or bar graph is a chart with rectangular bars with lengths proportional to the values that they represent. @@ -202,7 +202,7 @@ {{{ switch to the slide which says about log-log graph }}} -Now let us move on to log-log plot. A log-log graph or log-log plot is +Now let us move on to the log-log plot. A log-log graph or a log-log plot is a two-dimensional graph of numerical data that uses logarithmic scales on both the horizontal and vertical axes. Because of the nonlinear scaling of the axes, a function of the form y = ax\ :sup:`b` will diff -r 8249ae9d570a -r 88a01948450d parsing_data/script.rst --- a/parsing_data/script.rst Wed Nov 17 23:24:23 2010 +0530 +++ b/parsing_data/script.rst Wed Nov 17 23:24:57 2010 +0530 @@ -13,9 +13,10 @@ .. 1. Getting started with lists .. Author : Nishanth Amuluru - Internal Reviewer : + Internal Reviewer : Amit External Reviewer : - Checklist OK? : [2010-10-05] + Language Reviewer : Bhanukiran + Checklist OK? : [2010-10-05] Script ------ @@ -37,7 +38,7 @@ #[Puneeth]: I don't like the way the term "parsing data" has been used, all through the script. See if that can be changed. - Lets us have a look at the problem + Let us have a look at the problem {{{ Show the slide containing problem statement. }}} @@ -48,9 +49,9 @@ As you can see, each record consists of fields seperated by a ";". The first record is region code, then roll number, then name, marks of second language, first language, maths, science and social, total marks, pass/fail indicatd by P -or F and finally W if with held and empty otherwise. +or F and finally W if withheld and empty otherwise. -Our job is to calculate the mean of all the maths marks in the region "B". +Our job is to calculate the arithmetic mean of all the maths marks in the region "B". #[Nishanth]: Please note that I am not telling anything about AA since they do not know about any if/else yet. @@ -143,7 +144,7 @@ white space. The only road block we now have is conversion of string to float. The splitting and stripping operations are done on a string and their result is -also a string. hence the marks that we have are still strings and mathematical +also a string. Hence the marks that we have are still strings and mathematical operations are not possible on them. We must convert them into numbers (integers or floats), before we can perform mathematical operations on them. diff -r 8249ae9d570a -r 88a01948450d plotting-data/quickref.tex --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/plotting-data/quickref.tex Wed Nov 17 23:24:57 2010 +0530 @@ -0,0 +1,15 @@ +Creating a Sequence:\\ +{\ex \lstinline| L = [0.1, 0.2, 0.3] |} + +Squaring a sequence:\\ +{\ex \lstinline| tsquare=square(t) |} + +Plotting two list using small dots:\\ +{\ex \lstinline| plot(L,tsquare,'.') |} + +Plotting two list using big dots:\\ +{\ex \lstinline| plot(L,tsquare,'o') |} + +Plotting an errorbar in blue color:\\ +{\ex \lstinline| errorbar(L,tsquare,xerr=delta_L, yerr=delta_T, fmt='b.') |} + diff -r 8249ae9d570a -r 88a01948450d savefig/script.rst --- a/savefig/script.rst Wed Nov 17 23:24:23 2010 +0530 +++ b/savefig/script.rst Wed Nov 17 23:24:57 2010 +0530 @@ -17,7 +17,8 @@ .. Author : Anoop Jacob Thomas Internal Reviewer : Puneeth External Reviewer : - Checklist OK? : [2010-10-05] + Language Reviewer : Bhanukiran + Checklist OK? : <10-11-2010, Anand, OK> [2010-10-05] .. #[Puneeth: Quickref missing.] @@ -93,7 +94,7 @@ {{{ Highlight the .png part using mouse movements }}} -Here I have used an extension ``.png`` which means i want to save the +Here I have used an extension ``.png`` which means I want to save the image as a PNG file. Now let us locate ``sine.png`` file saved. We saved the file to diff -r 8249ae9d570a -r 88a01948450d sets/script.rst --- a/sets/script.rst Wed Nov 17 23:24:23 2010 +0530 +++ b/sets/script.rst Wed Nov 17 23:24:57 2010 +0530 @@ -15,9 +15,10 @@ .. 1. Getting started with lists .. Author : Nishanth Amuluru - Internal Reviewer : + Internal Reviewer : Punch External Reviewer : - Checklist OK? : [2010-10-05] + Language Reviewer : Bhanukiran + Checklist OK? : <15-11-2010, Anand, OK> [2010-10-05] Script ------ diff -r 8249ae9d570a -r 88a01948450d testing-debugging/questions.rst --- a/testing-debugging/questions.rst Wed Nov 17 23:24:23 2010 +0530 +++ b/testing-debugging/questions.rst Wed Nov 17 23:24:57 2010 +0530 @@ -3,20 +3,49 @@ .. A mininum of 8 questions here (along with answers) -1. Question 1 +1. Why do we do Software Testing? + + Answer: To evaluate a program and determine that it meets required results. + + - Answer: Answer 1 + +2. What is proper indentation for python code according to style guidelines? + + Answer: Four Space Indentation - OR +3. What is the idiom used for running python scripts in a standalone manner? - Answer:: + Answer: + if __name__ == '__main__': + +4. What constitutes a test case? + + Answer: A set of inputs and expected result + +5. How do you start the debugger on ipython? + + Answer: %debug + +6. What idiom do you use for catching and exception? + + Answer: try,catch. + +7. What kind of exception is 0/0? + + Answer Zero Division Error + +8. a = 12.68 + b = 0.05 + c = round(a/b) + d = c * b + + What would you recommend to the programmer who wrote + above written piece of code. + - answer code line 1 - answer code line 2 - answer code line 3 -2. Question 2 -3. Question 3 + Larger Questions @@ -24,5 +53,8 @@ .. A minimum of 2 questions here (along with answers) -1. Question 1 -2. Question 2 +1. Write a program for checking if two numbers are coprime + Create test cases for it and automate it. +2. Write a program that divides two numbers. Take the numbers from the user. Also make sure the code tell the user that input is invalid incase the divisor is 0. + + diff -r 8249ae9d570a -r 88a01948450d testing-debugging/quickref.tex --- a/testing-debugging/quickref.tex Wed Nov 17 23:24:23 2010 +0530 +++ b/testing-debugging/quickref.tex Wed Nov 17 23:24:57 2010 +0530 @@ -1,8 +1,28 @@ -Creating a linear array:\\ -{\ex \lstinline| x = linspace(0, 2*pi, 50)|} +Skeleton of a test:\\ +{\ex \lstinline| if __name__ == '__main__':|} +{\ex \lstinline| result = gcd(48, 64) |} +{\ex \lstinline| if result != 16: |} +{\ex \lstinline| print ``Test Failed'' |} +{\ex \lstinline| print ``Test Passed'' |} + + +\textbf{Testing} + +Get results from function or unit of code being tested.Compare it to original output. Test passed if they match else failed. -Plotting two variables:\\ -{\ex \lstinline| plot(x, sin(x))|} +\textbf{Code Style} +Four Space Indentation +79 character limit on a line +Funtions should be seperated by +blank line +Use Docstring +White space around operators + +Skeleton of try catch:\\ +{\ex \lstinline| try: |} +{\ex \lstinline| num = int(a) |} +{\ex \lstinline| except: |} +{\ex \lstinline| print ``Wrong input...'' |} -Plotting two lists of equal length x, y:\\ -{\ex \lstinline| plot(x, y)|} +Starting debugger in ipython:\\ +{\ex \lstinline| %debug |} diff -r 8249ae9d570a -r 88a01948450d testing-debugging/script.rst --- a/testing-debugging/script.rst Wed Nov 17 23:24:23 2010 +0530 +++ b/testing-debugging/script.rst Wed Nov 17 23:24:57 2010 +0530 @@ -68,7 +68,7 @@ if __name__ == '__main__': result = gcd(48, 64) if result != 16: - print "Test failed for the case a=48 and b=64. Expected 16. Obtained %d instead." % result + print "Test failed" print "Test Passed" Note that we have introduced a new semantic which uses two new magic names @@ -173,15 +173,15 @@ 1.Four Space Indentation 2.Limit to 79 characters a line, but readability should come first. 3.Functions and methods should be separated with two blank lines. - Class definitions with three blank lines. 4.No inline comments, comments should be above the line they comment. 5.Use Docstring to explain units of code performing specific task like functions. 6.We should always have whitespace around operators and after punctuation. %% %% Pause and do the following exercise -%% %% Give meaningful names to the variables in the gcd code . - +%% %% Give meaningful names to the variables in following +code + c=a/b This will help enormously towards making our program more readable. @@ -217,10 +217,10 @@ Lets see why and how we can use Exception in our programs. -{{{ Slide with code snippet }}} + Type on your interpreter:: - + a = raw_input("Enter a number:") num = int(a) @@ -258,7 +258,7 @@ Test if it is correct by changing the code. And refine the hypothesis on the basis of our result. -{{{ Slide with code snippet }}} + Lets see another example of debugging. Create a file mymodule.py and add the following code:: @@ -267,13 +267,16 @@ total=1+1 print spam -{{{ Slide with code snippet }}} + Lets now try and run this code :: import mymodule mymodule.test() + +{{{ Slide with idb and total being accessed }}} + Interpreter gives us an error because spam is not defined but lets now do %debug on ipython interpreter. The prompt on the shell has changed to ipdb. This is debugger here you can access variables in that code block for example 'total'unlike the normal interpreter. diff -r 8249ae9d570a -r 88a01948450d testing-debugging/slides.org --- a/testing-debugging/slides.org Wed Nov 17 23:24:23 2010 +0530 +++ b/testing-debugging/slides.org Wed Nov 17 23:24:57 2010 +0530 @@ -36,23 +36,18 @@ - Need for coding style and some of the standards followed by the Python Community. - Handling Errors and Exceptions. - * gcd function - Create gcd.py file with: -#+begin_LaTeX -\begin{lstlisting}[language=python] +#+begin_src python def gcd(a, b): if a % b == 0: return b return gcd(b, a%b) -\end{lstlisting} -#+end_LaTeX +#+end_src python * Test for gcd.py - Edit gcd.py file -#+begin_LaTeX -\begin{lstlisting}[language=python] - +#+begin_src python def gcd(a, b): if b == 0: return a @@ -63,13 +58,11 @@ if result != 16: print "Test failed" print "Test Passed" -\end{lstlisting} -#+end_LaTeX + +#+end_src * Automating tests -#+begin_LaTeX -\begin{lstlisting}[language=python] - +#+begin_src python if __name=__='__main__': for line in open('numbers.txt'): numbers = line.split() @@ -79,8 +72,138 @@ if gcd(x, y) != result: print "Failed gcd test for", x, y +#+end_src + +* Question 1 + For the same inputs as gcd write automated tests for LCM. +* Solution 1 +#+begin_src python + def gcd(a, b): + if a % b == 0: + return b + return gcd(b, a%b) + + def lcm(a, b): + return (a * b) / gcd(a, b) + + if __name__ == '__main__': + for line in open('lcmtestcases.txt'): + numbers = line.split() + x = int(numbers[0]) + y = int(numbers[1]) + result = int(numbers[2]) + if lcm(x, y) != result: + print "Failed lcm test for", x, y + +#+end_src + +* Meaning full names +#+begin_src python + + amount = 12.68 + denom = 0.05 + nCoins = round(amount / denom) + rAmount = nCoins * denom + +#+end_src + +* Code style + - Four Space Indentation + - 79 character limit on a line + - Funtions should be seperated by + blank line + - Use Docstring + - White space around operators + - l = 32 % 4 + +* Question 2 + - Give meaningful names to the variables in following + code + + - c = a / b + +* Solution 2 +#+begin_src python + + quotient = dividend / divisor + +#+end_src + +* Code Snippet +#+begin_src python + + while True print 'Hello world' + +#+end_src + +* Error +#+begin_latex +\begin{lstlisting} + while True print 'Hello world' + \end{lstlisting} + \begin{lstlisting} + File "", line 1, in ? + while True print 'Hello world' +SyntaxError: invalid syntax \end{lstlisting} -#+end_LaTeX +#+end_latex + +* Code Snippet +#+begin_src python + a = raw_input("Enter a number") + try: + num = int(a) + except: + print "Wrong input ..." + +#+end_src + +* Using idb +#+begin_latex +\small +\begin{lstlisting} +In []: import mymodule +In []: mymodule.test() +--------------------------------------------- +NameError Traceback (most recent call last) + in () +mymodule.py in test() + 1 def test(): + 2 total=1+1 +----> 3 print spam +NameError: global name 'spam' is not defined + +In []: %debug +> mymodule.py(2)test() + 0 print spam +ipdb> total +2 +\end{lstlisting} + +#+end_latex +* Summary + - Create simple tests for a function. + - Learn to Automate tests using many predefined test cases. + - Good coding standards. + - Difference between syntax error and exception. + - Handling exception using try and except. + - Using %debug for debugging on ipython. + +* Thank you! +#+begin_latex + \begin{block}{} + \begin{center} + This spoken tutorial has been produced by the + \textcolor{blue}{FOSSEE} team, which is funded by the + \end{center} + \begin{center} + \textcolor{blue}{National Mission on Education through \\ + Information \& Communication Technology \\ + MHRD, Govt. of India}. + \end{center} + \end{block} +#+end_latex + diff -r 8249ae9d570a -r 88a01948450d testing-debugging/slides.tex --- a/testing-debugging/slides.tex Wed Nov 17 23:24:23 2010 +0530 +++ b/testing-debugging/slides.tex Wed Nov 17 23:24:57 2010 +0530 @@ -1,4 +1,4 @@ -% Created 2010-11-07 Sun 18:57 +% Created 2010-11-12 Fri 02:00 \documentclass[presentation]{beamer} \usepackage[latin1]{inputenc} \usepackage[T1]{fontenc} @@ -61,12 +61,12 @@ \item Create gcd.py file with: \end{itemize} -\begin{lstlisting}[language=python] - def gcd(a, b): - if a % b == 0: - return b - return gcd(b, a%b) -\end{lstlisting} +\begin{verbatim} +def gcd(a, b): + if a % b == 0: + return b + return gcd(b, a%b) +\end{verbatim} \end{frame} \begin{frame}[fragile] \frametitle{Test for gcd.py} @@ -76,45 +76,203 @@ \item Edit gcd.py file \end{itemize} -\begin{lstlisting}[language=python] +\begin{verbatim} +def gcd(a, b): + if b == 0: + return a + return gcd(b, a%b) - def gcd(a, b): - if b == 0: - return a - return gcd(b, a%b) - - if __name__=='__main__': - result = gcd(48, 64) - if result != 16: - print "Test failed" - print "Test Passed" -\end{lstlisting} +if __name__=='__main__': + result = gcd(48, 64) + if result != 16: + print "Test failed" + print "Test Passed" +\end{verbatim} \end{frame} \begin{frame}[fragile] \frametitle{Automating tests} \label{sec-4} -\begin{lstlisting}[language=python] +\begin{verbatim} +if __name=__='__main__': +for line in open('numbers.txt'): + numbers = line.split() + x = int(numbers[0]) + y = int(numbers[1]) + result = int(numbers[2]) + if gcd(x, y) != result: + print "Failed gcd test + for", x, y +\end{verbatim} +\end{frame} +\begin{frame} +\frametitle{Question 1} +\label{sec-5} + + For the same inputs as gcd write automated tests for LCM. +\end{frame} +\begin{frame}[fragile] +\frametitle{Solution 1} +\label{sec-6} + +\begin{verbatim} +def gcd(a, b): + if a % b == 0: + return b + return gcd(b, a%b) + + def lcm(a, b): + return (a * b) / gcd(a, b) + + if __name__ == '__main__': + for line in open('lcmtestcases.txt'): + numbers = line.split() + x = int(numbers[0]) + y = int(numbers[1]) + result = int(numbers[2]) + if lcm(x, y) != result: + print "Failed lcm test for", x, y +\end{verbatim} +\end{frame} +\begin{frame}[fragile] +\frametitle{Meaning full names} +\label{sec-7} + +\begin{verbatim} + +amount = 12.68 +denom = 0.05 +nCoins = round(amount / denom) +rAmount = nCoins * denom +\end{verbatim} +\end{frame} +\begin{frame} +\frametitle{Code style} +\label{sec-8} + +\begin{itemize} +\item Four Space Indentation +\item 79 character limit on a line +\item Funtions should be seperated by + blank line +\item Use Docstring +\item White space around operators + +\begin{itemize} +\item l = 32 \% 4 +\end{itemize} + +\end{itemize} +\end{frame} +\begin{frame} +\frametitle{Question 2} +\label{sec-9} + +\begin{itemize} +\item Give meaningful names to the variables in following + code + +\begin{itemize} +\item c = a / b +\end{itemize} + +\end{itemize} +\end{frame} +\begin{frame}[fragile] +\frametitle{Solution 2} +\label{sec-10} - if __name=__='__main__': - for line in open('numbers.txt'): - numbers = line.split() - x = int(numbers[1]) - y = int(numbers[2]) - result = int(numbers[3]) - if gcd(x, y) != result: - print "Failed gcd test - for", x, y +\begin{verbatim} + +quotient = dividend / divisor +\end{verbatim} +\end{frame} +\begin{frame}[fragile] +\frametitle{Code Snippet} +\label{sec-11} + +\begin{verbatim} + +while True print 'Hello world' +\end{verbatim} +\end{frame} +\begin{frame}[fragile] +\frametitle{Error} +\label{sec-12} + +\begin{lstlisting} + while True print 'Hello world' + \end{lstlisting} + \begin{lstlisting} + File "", line 1, in ? + while True print 'Hello world' +SyntaxError: invalid syntax \end{lstlisting} - +\end{frame} +\begin{frame}[fragile] +\frametitle{Code Snippet} +\label{sec-13} +\begin{verbatim} +a = raw_input("Enter a number") +try: + num = int(a) + except: + print "Wrong input ..." +\end{verbatim} +\end{frame} +\begin{frame}[fragile] +\frametitle{Using idb} +\label{sec-14} +\small +\begin{lstlisting} +In []: import mymodule +In []: mymodule.test() +--------------------------------------------- +NameError Traceback (most recent call last) + in () +mymodule.py in test() + 1 def test(): + 2 total=1+1 +----> 3 print spam +NameError: global name 'spam' is not defined -$^{1}$ FOOTNOTE DEFINITION NOT FOUND: 0 +In []: %debug +> mymodule.py(2)test() + 0 print spam +ipdb> total +2 +\end{lstlisting} +\end{frame} +\begin{frame} +\frametitle{Summary} +\label{sec-15} -$^{2}$ FOOTNOTE DEFINITION NOT FOUND: 1 +\begin{itemize} +\item Create simple tests for a function. +\item Learn to Automate tests using many predefined test cases. +\item Good coding standards. +\item Difference between syntax error and exception. +\item Handling exception using try and except. +\item Using \%debug for debugging on ipython. +\end{itemize} +\end{frame} +\begin{frame} +\frametitle{Thank you!} +\label{sec-16} -$^{3}$ FOOTNOTE DEFINITION NOT FOUND: 2 + \begin{block}{} + \begin{center} + This spoken tutorial has been produced by the + \textcolor{blue}{FOSSEE} team, which is funded by the + \end{center} + \begin{center} + \textcolor{blue}{National Mission on Education through \\ + Information \& Communication Technology \\ + MHRD, Govt. of India}. + \end{center} + \end{block} \end{frame} \end{document} diff -r 8249ae9d570a -r 88a01948450d tuples/script.rst --- a/tuples/script.rst Wed Nov 17 23:24:23 2010 +0530 +++ b/tuples/script.rst Wed Nov 17 23:24:57 2010 +0530 @@ -13,9 +13,10 @@ .. 1. Getting started with lists .. Author : Nishanth Amuluru - Internal Reviewer : + Internal Reviewer : Punch External Reviewer : - Checklist OK? : [2010-10-05] + Language Reviewer : Bhanukiran + Checklist OK? : [2010-10-05] Script ------ diff -r 8249ae9d570a -r 88a01948450d using python modules/script.rst --- a/using python modules/script.rst Wed Nov 17 23:24:23 2010 +0530 +++ b/using python modules/script.rst Wed Nov 17 23:24:57 2010 +0530 @@ -20,7 +20,8 @@ .. Author : Anoop Jacob Thomas Internal Reviewer : Puneeth External Reviewer : - Checklist OK? : [2010-10-05] + Language Reviewer : Bhanukiran + Checklist OK? : <11-11-2010, Anand, OK> [2010-10-05] ==================== diff -r 8249ae9d570a -r 88a01948450d using-plot-interactively/script.rst --- a/using-plot-interactively/script.rst Wed Nov 17 23:24:23 2010 +0530 +++ b/using-plot-interactively/script.rst Wed Nov 17 23:24:57 2010 +0530 @@ -21,11 +21,10 @@ Script ------- - +{{{ Show the Title Slide }}} Hello and welcome to the tutorial on creating simple plots using Python.This tutorial is presented by the Fossee group. -{{{ Show the Title Slide }}} I hope you have IPython running on your computer. @@ -52,13 +51,11 @@ {{{ Slide with Error written on it }}} - - Then you have to install matplotlib and run this command again. Now type in your ipython shell :: - In[]: linpace? + linpace? @@ -66,20 +63,20 @@ calculated over the interval start and stop. To illustrate this, lets do it form 1 to 100 and try 100 points. :: - In[]: linspace(1,100,100) + linspace(1,100,100) As you can see a sequence of numbers from 1 to 100 appears. Now lets try 200 points between 0 and 1 you do this by typing :: - In[]: linspace(0,1,200) + linspace(0,1,200) 0 for start , 1 for stop and 200 for no of points. In linspace the start and stop points can be integers, decimals , or constants. Let's try and get 100 points between -pi to pi. Type :: - In[]: p = linspace(-pi,pi,100) + p = linspace(-pi,pi,100) 'pi' here is constant defined by pylab. Save this to the variable, p @@ -87,17 +84,17 @@ If you now :: - In[]: len(p) + len(p) You will get the no. of points. len function gives the no of elements of a sequence. Let's try and plot a cosine curve between -pi and pi using these -points. Simply type :: +points. Simply type:: + plot(p,cos(points)) - In[]: plot(p,cos(points)) Here cos(points) gets the cosine value at every corresponding point to p. @@ -106,15 +103,15 @@ We can also save cos(points) to variable cosine and plot it using plot.:: - In[]: cosine=cos(points) + cosine=cos(points) - In[]: plot(p,cosine) + plot(p,cosine) Now do :: - In[]: clf() + clf() this will clear the plot. @@ -124,7 +121,7 @@ plot. :: - In []: plot(p,sin(p)) + plot(p,sin(p)) @@ -144,37 +141,57 @@ -{{{ Action corelating with the words }}} +{{{ Show how to save the file }}} As you can see I can specify format of file from the dropdown. -Formats like png ,eps ,pdf, ps are available. +Formats like png ,eps ,pdf, ps are available. -Left to the save button is the slider button to specify the margins. +Left to the save button is the slider button to specify the margins. -{{{ Action corelating with the words }}} +{{{ Show how to zoom. Press zoom button and specify region to zoom }}} Left to this is zoom button to zoom into the plot. Just specify the region to zoom into. + +{{{ Press Move button and move the axes. }}} + The button left to it can be used to move the axes of the plot. -{{{ Action corelating with the words }}} +{{{ Press Back and Forward Button }}} The next two buttons with a left and right arrow icons change the state of the plot and take it to the previous state it was in. It more or less acts like a back and forward button in the browser. -{{{ Action corelating with the words }}} +{{{ Press home button }}} The last one is 'home' referring to the initial plot. -{{{ Action corelating with the words}}} + + + +Following is an exercise that you must do. + +%% %% Plot (sin(x)*sin(x))/x . + 1. Save the plot by the sinsquarebyx.pdf in pdf format. + 2. Zoom and find the maxima. + + 3. Bring it back to initial position. + + +Please, pause the video here. Do the exercise and then continue. + + + + + + {{{ Summary Slide }}} - In this tutorial we have looked at 1. Starting Ipython with pylab @@ -190,10 +207,7 @@ 5. Using the UI of plot for studying it better . Using functionalities like save , zoom and moving the plots on x and y axis - - - -{{{ Show the "sponsored by FOSSEE" slide }}} + {{{ Show the "sponsored by FOSSEE" slide }}} diff -r 8249ae9d570a -r 88a01948450d using-plot-interactively/slides.org --- a/using-plot-interactively/slides.org Wed Nov 17 23:24:23 2010 +0530 +++ b/using-plot-interactively/slides.org Wed Nov 17 23:24:57 2010 +0530 @@ -2,36 +2,75 @@ #+LaTeX_CLASS_OPTIONS: [presentation] #+BEAMER_FRAME_LEVEL: 1 -#+BEAMER_HEADER_EXTRA: \usetheme{Warsaw}\useoutertheme{infolines}\usecolortheme{default}\setbeamercovered{transparent} +#+BEAMER_HEADER_EXTRA: \usetheme{Warsaw}\usecolortheme{default}\useoutertheme{infolines}\setbeamercovered{transparent} #+COLUMNS: %45ITEM %10BEAMER_env(Env) %10BEAMER_envargs(Env Args) %4BEAMER_col(Col) %8BEAMER_extra(Extra) #+PROPERTY: BEAMER_col_ALL 0.1 0.2 0.3 0.4 0.5 0.6 0.7 0.8 0.9 1.0 :ETC -#+OPTIONS: H:5 num:t toc:nil \n:nil @:t ::t |:t ^:t -:t f:t *:t <:t + +#+LaTeX_CLASS: beamer +#+LaTeX_CLASS_OPTIONS: [presentation] -#+TITLE: Plotting Data -#+AUTHOR: FOSSEE -#+DATE: 2010-09-14 Tue -#+EMAIL: info@fossee.in +#+LaTeX_HEADER: \usepackage[english]{babel} \usepackage{ae,aecompl} +#+LaTeX_HEADER: \usepackage{mathpazo,courier,euler} \usepackage[scaled=.95]{helvet} + +#+LaTeX_HEADER: \usepackage{listings} + +#+LaTeX_HEADER:\lstset{language=Python, basicstyle=\ttfamily\bfseries, +#+LaTeX_HEADER: commentstyle=\color{red}\itshape, stringstyle=\color{darkgreen}, +#+LaTeX_HEADER: showstringspaces=false, keywordstyle=\color{blue}\bfseries} -# \author[FOSSEE] {FOSSEE} +#+TITLE: Using Plot Interactively +#+AUTHOR: FOSSEE +#+EMAIL: +#+DATE: -# \institute[IIT Bombay] {Department of Aerospace Engineering\\IIT Bombay} -# \date{} +#+DESCRIPTION: +#+KEYWORDS: +#+LANGUAGE: en +#+OPTIONS: H:3 num:nil toc:nil \n:nil @:t ::t |:t ^:t -:t f:t *:t <:t +#+OPTIONS: TeX:t LaTeX:nil skip:nil d:nil todo:nil pri:nil tags:not-in-toc -* Tutorial Plan -** Creating a simple plot -** Use the buttons on window to study the plot +* Outline + - Plot a simple mathemaical function. + - Using the User Interface of plot figure. * Error if Ipython not installed ** `ERROR: matplotlib could NOT be imported! Starting normal IPython.` + * Plot UI - -* Summary +#+begin_latex + \includegraphics[height=0.12in, interpolate=true]{buttons} +#+end_latex + - Save + - Zoom + - Move axis + - Back and Forward Button + - Home -** Start Ipython with pylab -** Using linspace -** Finding length of sequnces using len. -** Plotting mathematical functions using plot. -** Clearing drawing area using clf -** Using the UI of plot + +* Summary + - Plotting mathematical functions using plot. + - Using the UI of plot + - Save + - Zoom + - Move axis + - Back and Forward Button + - Home + +* Thank You! +#+begin_latex + \begin{block}{} + \begin{center} + This spoken tutorial has been produced by the + \textcolor{blue}{FOSSEE} team, which is funded by the + \end{center} + \begin{center} + \textcolor{blue}{National Mission on Education through \\ + Information \& Communication Technology \\ + MHRD, Govt. of India}. + \end{center} + \end{block} +#+end_latex + + diff -r 8249ae9d570a -r 88a01948450d using-plot-interactively/slides.tex --- a/using-plot-interactively/slides.tex Wed Nov 17 23:24:23 2010 +0530 +++ b/using-plot-interactively/slides.tex Wed Nov 17 23:24:57 2010 +0530 @@ -1,35 +1,52 @@ -% Created 2010-10-20 Wed 21:57 +% Created 2010-11-11 Thu 13:15 \documentclass[presentation]{beamer} -\usetheme{Warsaw}\useoutertheme{infolines}\usecolortheme{default}\setbeamercovered{transparent} \usepackage[latin1]{inputenc} \usepackage[T1]{fontenc} +\usepackage{fixltx2e} \usepackage{graphicx} \usepackage{longtable} \usepackage{float} \usepackage{wrapfig} \usepackage{soul} +\usepackage{t1enc} +\usepackage{textcomp} +\usepackage{marvosym} +\usepackage{wasysym} +\usepackage{latexsym} \usepackage{amssymb} \usepackage{hyperref} - +\tolerance=1000 +\usepackage[english]{babel} \usepackage{ae,aecompl} +\usepackage{mathpazo,courier,euler} \usepackage[scaled=.95]{helvet} +\usepackage{listings} +\lstset{language=Python, basicstyle=\ttfamily\bfseries, +commentstyle=\color{red}\itshape, stringstyle=\color{darkgreen}, +showstringspaces=false, keywordstyle=\color{blue}\bfseries} +\providecommand{\alert}[1]{\textbf{#1}} -\title{Plotting Data } +\title{Using Plot Interactively} \author{FOSSEE} -\date{2010-09-14 Tue} +\date{} +\usetheme{Warsaw}\usecolortheme{default}\useoutertheme{infolines}\setbeamercovered{transparent} \begin{document} \maketitle -\begin{frame} -\frametitle{Tutorial Plan} -\label{sec-1} -\begin{itemize} + + + + + + -\item Creating a simple plot\\ -\label{sec-1.1}% -\item Use the buttons on window to study the plot\\ -\label{sec-1.2}% -\end{itemize} % ends low level + +\begin{frame} +\frametitle{Outline} +\label{sec-1} + + How to plot a simple mathematical function. + Using the User Interface of plot figure. \end{frame} \begin{frame} \frametitle{Error if Ipython not installed} @@ -37,35 +54,46 @@ \begin{itemize} \item `ERROR: matplotlib could NOT be imported! Starting normal IPython.`\\ -\label{sec-2.1}% +\label{sec-2_1}% \end{itemize} % ends low level \end{frame} \begin{frame} \frametitle{Plot UI} \label{sec-3} + + \includegraphics[height=0.12in, interpolate=true]{buttons} +\begin{itemize} +\item Save +\item Zoom +\item Move axis +\item Back and Forward Button +\item Home +\end{itemize} + + + +\end{frame} \begin{frame} - \begin{center} - \includegraphics[height=1.0in,width=4.2in]{buttons.png} - \end{center} -\end{frame} - \frametitle{Summary} \label{sec-4} + \begin{itemize} +\item Plotting mathematical functions using plot. + \includegraphics[height=0.12in, interpolate=true]{buttons} +\item Using the UI of plot -\item Start Ipython with pylab\\ -\label{sec-4.1}% -\item Using linspace\\ -\label{sec-4.2}% -\item Finding length of sequnces using len.\\ -\label{sec-4.3}% -\item Plotting mathematical functions using plot.\\ -\label{sec-4.4}% -\item Clearing drawing area using clf\\ -\label{sec-4.5}% -\item Using the UI of plot\\ -\label{sec-4.6}% -\end{itemize} % ends low level +\begin{itemize} +\item Save +\item Zoom +\item Move axis +\item Back and Forward Button +\item Home +\end{itemize} + +\end{itemize} + + + \end{frame} \end{document} diff -r 8249ae9d570a -r 88a01948450d using_sage_to_teach/script.rst --- a/using_sage_to_teach/script.rst Wed Nov 17 23:24:23 2010 +0530 +++ b/using_sage_to_teach/script.rst Wed Nov 17 23:24:57 2010 +0530 @@ -14,7 +14,8 @@ .. Author : Nishanth Amuluru Internal Reviewer : External Reviewer : - Checklist OK? : [2010-10-05] + Language Reviewer : Bhanukiran + Checklist OK? : [2010-10-05] Script ------ diff -r 8249ae9d570a -r 88a01948450d writing_python_scripts/script.rst --- a/writing_python_scripts/script.rst Wed Nov 17 23:24:23 2010 +0530 +++ b/writing_python_scripts/script.rst Wed Nov 17 23:24:57 2010 +0530 @@ -12,9 +12,10 @@ .. 1. Using Python modules .. Author : Nishanth Amuluru - Internal Reviewer : + Internal Reviewer : Punch External Reviewer : - Checklist OK? : [2010-10-05] + Language Reviewer : Bhanukiran + Checklist OK? : <15-11-2010, Anand, OK> [2010-10-05] Script ------ @@ -46,7 +47,7 @@ return a -We shall write an test function in the script that tests the gcd function every +We shall write a test function in the script that tests the gcd function every time the script is run. {{{ Add to the script }}}