diff --git a/en-US/datastructure.xml b/en-US/datastructure.xml
index 3f96b88..9b36157 100644
--- a/en-US/datastructure.xml
+++ b/en-US/datastructure.xml
@@ -10,9 +10,7 @@
Lists
-
->> a = [23, 45, 1, -3434, 43624356, 234]
+>> a = [23, 45, 1, -3434, 43624356, 234]
>>> a.append(45)
>>> a
[23, 45, 1, -3434, 43624356, 234, 45]
@@ -21,9 +19,7 @@
At first we created a list a. Then to add 45 at the end of the list we call a.append(45) method. You can see that 45 added at the end of the list. Sometimes it may require to insert data at any place within the list, for that we have insert() method.
-
->> a.insert(0, 1) # 1 added at the 0th position of the list
+>> a.insert(0, 1) # 1 added at the 0th position of the list
>>> a
[1, 23, 45, 1, -3434, 43624356, 234, 45]
>>> a.insert(0, 111)
@@ -34,18 +30,14 @@
count(s) will return you number of times s is in the list. Here we are going to check how many times 45 is there in the list.
-
->> a.count(45)
+>> a.count(45)
2
]]>
If you want to any particular value from the list you have to use remove() method.
-
->> a.remove(234)
+>> a.remove(234)
>>> a
[111, 1, 23, 45, 1, -3434, 43624356, 45]
]]>
@@ -53,9 +45,7 @@
Now to reverse the whole list
-
->> a.reverse()
+>> a.reverse()
>>> a
[45, 43624356, -3434, 1, 45, 23, 1, 111]
]]>
@@ -63,9 +53,7 @@
We can store anything in the list, so first we are going to add another list b in a , then we will learn how to add the values of b into a .
-
->> b = [45, 56, 90]
+>> b = [45, 56, 90]
>>> a.append(b)
>>> a
[45, 43624356, -3434, 1, 45, 23, 1, 111, [45, 56, 90]]
@@ -81,34 +69,28 @@
Above you can see how we used a.extend() method to extend the list. To sort any list we have sort() method.
-
->> a.sort()
+>> a.sort()
>>> a
[-3434, 1, 1, 23, 45, 45, 45, 56, 90, 111, 43624356, [45, 56, 90]]
]]>
-
+
You can also delete element at any particular position of the list using the del keyword.
-
->> del a[-1]
+>> del a[-1]
>>> a
[-3434, 1, 1, 23, 45, 45, 45, 56, 90, 111, 43624356]
]]>
-
+
-
+
Using lists as stack and queue
Stacks are often known as LIFO (Last In First Out) structure. It means the data will enter into it at the end , and the last data will come out first. The easiest example can be of couple of marbles in an one side closed pipe. So if you want to take the marbles out of it you have to do that from the end where you entered the last marble. To achieve the same in code
-
->> a
+>> a
[1, 2, 3, 4, 5, 6]
>>> a.pop()
6
@@ -124,16 +106,14 @@
>>> a
[1, 2, 34)
]]>
-
+
We learned a new method above pop(). pop(i) will take out the ith data from the list.
In our daily life we have to encounter queues many times, like in ticket counters or in library or in the billing section of any supermarket. Queue is the data structure where you can append more data at the end and take out data from the beginning. That is why it is known as FIFO (First In First Out).
-
->> a = [1, 2, 3, 4, 5]
+>> a = [1, 2, 3, 4, 5]
>>> a.append(1)
>>> a
[1, 2, 3, 4, 5, 1]
@@ -147,7 +127,7 @@
To take out the first element of the list we are using a.pop(0).
-
+
@@ -158,9 +138,7 @@
For example if we want to make a list out of the square values of another list, then
-
->> a = [1, 2, 3]
+>> a = [1, 2, 3]
>>> [x ** 2 for x in a]
[1, 4, 9]
>>> z = [x + 1 for x in [x ** 2 for x in a]]
@@ -179,9 +157,7 @@
Tuples are data separated by comma.
-
->> a = 'Fedora', 'Debian', 'Kubuntu', 'Pardus'
+>> a = 'Fedora', 'Debian', 'Kubuntu', 'Pardus'
>>> a
('Fedora', 'Debian', 'Kubuntu', 'Pardus')
>>> a[1]
@@ -195,9 +171,7 @@ Fedora Debian Kubuntu Pardus
You can also unpack values of any tuple in to variables, like
-
->> divmod(15,2)
+>> divmod(15,2)
(7, 1)
>>> x, y = divmod(15,2)
>>> x
@@ -209,9 +183,7 @@ Fedora Debian Kubuntu Pardus
Tuples are immutable, that means you can not del/add/edit any value inside the tuple. Here is another example
-
->> a = (1, 2, 3, 4)
+>> a = (1, 2, 3, 4)
>>> del a[0]
Traceback (most recent call last):
File "", line 1, in
@@ -219,14 +191,12 @@ TypeError: 'tuple' object doesn't support item deletion
]]>
- Above you can see python is giving error when we are trying to delete a value in the tuple.
-
+ Above you can see python is giving error when we are trying to delete a value in the tuple.
+
To create a tuple which contains only one value you have to type a trailing comma.
-
->> a = (123)
+>> a = (123)
>>> a
123
>>> type(a)
@@ -237,13 +207,11 @@ TypeError: 'tuple' object doesn't support item deletion
>>> type(a)
]]>
-
+
Using the buitin function type() you can know the data type of any variable. Remember the len() function we used to find the length of any sequence ?
-
->> type(len)
+>> type(len)
]]>
@@ -252,21 +220,17 @@ TypeError: 'tuple' object doesn't support item deletion
Sets
- Sets are another type of data structure with no duplicate items. We can also mathematical set operations on sets.
+ Sets are another type of data structure with no duplicate items. We can also mathematical set operations on sets.
-
->> a = set('abcthabcjwethddda')
+>> a = set('abcthabcjwethddda')
>>> a
set(['a', 'c', 'b', 'e', 'd', 'h', 'j', 't', 'w'])
]]>
-
+
And some examples of the set operations
-
->> a = set('abracadabra')
+>> a = set('abracadabra')
>>> b = set('alacazam')
>>> a # unique letters in a
set(['a', 'r', 'b', 'c', 'd'])
@@ -279,19 +243,17 @@ set(['a', 'c'])
>>> a ^ b # letters in a or b but not both
set(['r', 'd', 'b', 'm', 'z', 'l'])
]]>
-
+
To add or pop values from a set
-
->> a
+>> a
set(['a', 'c', 'b', 'e', 'd', 'h', 'j', 'q', 't', 'w'])
>>> a.add('p')
>>> a
set(['a', 'c', 'b', 'e', 'd', 'h', 'j', 'q', 'p', 't', 'w'])
]]>
-
+
@@ -299,41 +261,33 @@ set(['a', 'c', 'b', 'e', 'd', 'h', 'j', 'q', 'p', 't', 'w'])
Dictionaries are unordered set of key: value pairs where keys are unique. We declare dictionaries using {} braces. We use dictionaries to store data for any particular key and then retrieve them.
-
->> data = {'kushal':'Fedora', 'kart_':'Debian', 'Jace':'Mac'}
+>> data = {'kushal':'Fedora', 'kart_':'Debian', 'Jace':'Mac'}
>>> data
{'kushal': 'Fedora', 'Jace': 'Mac', 'kart_': 'Debian'}
>>> data['kart_']
'Debian'
]]>
-
+
- We can add more data to it by simply
+ We can add more data to it by simply
-
->> data['parthan'] = 'Ubuntu'
+>> data['parthan'] = 'Ubuntu'
>>> data
{'kushal': 'Fedora', 'Jace': 'Mac', 'kart_': 'Debian', 'parthan': 'Ubuntu'}
]]>
-
+
To delete any particular key:value pair
-
->> del data['kushal']
+>> del data['kushal']
>>> data
{'Jace': 'Mac', 'kart_': 'Debian', 'parthan': 'Ubuntu'
]]>
-
+
To check if any key is there in the dictionary or not you can use has_key() or in keyword.
-
->> data.has_key('Soumya')
+>> data.has_key('Soumya')
False
>>> 'Soumya' in data
False
@@ -345,18 +299,14 @@ False
dict() can create dictionaries from tuples of key,value pair.
-
->> dict((('Indian','Delhi'),('Bangladesh','Dhaka')))
+>> dict((('Indian','Delhi'),('Bangladesh','Dhaka')))
{'Indian': 'Delhi', 'Bangladesh': 'Dhaka'}
]]>
If you want to loop through a dict use iteritems() method.
-
-
->> data
+
+>> data
{'Kushal': 'Fedora', 'Jace': 'Mac', 'kart_': 'Debian', 'parthan': 'Ubuntu'}
>>> for x, y in data.iteritems():
... print "%s uses %s" % (x, y)
@@ -370,22 +320,18 @@ parthan uses Ubuntu
If you want to loop through a list (or any sequence) and get iteration number at the same time you have to use enumerate().
-
->> for i, j in enumerate(['a', 'b', 'c']):
+>> for i, j in enumerate(['a', 'b', 'c']):
... print i, j
...
0 a
1 b
2 c
]]>
-
+
You may also need to iterate through two sequences same time, for that use zip() function.
-
-
->> a = ['Pradeepto', 'Kushal']
+
+>> a = ['Pradeepto', 'Kushal']
>>> b = ['OpenSUSE', 'Fedora']
>>> for x, y in zip(a, b):
... print "%s uses %s" % (x, y)
@@ -393,7 +339,7 @@ parthan uses Ubuntu
Pradeepto uses OpenSUSE
Kushal uses Fedora
]]>
-
+
@@ -401,9 +347,7 @@ Kushal uses Fedora
In this example , you have to take number of students as input , then ask marks for three subjects as 'Physics', 'Maths', 'History', if the total number for any student is less 120 then print he failed, or else say passed.
-
-
-
+
The output
-
-
-
-
-
+
+
+
matrixmul.py
In this example we will multiply two matrix's. First we will take input the number of rows/columns in the matrix (here we assume we are using n x n matrix). Then values of the matrix's.
-
-
-
+
The output
-
-
-
+
Here we have used list comprehensions couple of times. [int(x) for x in raw_input("").split(" ")] here first it takes the input as string by raw_input(), then split the result by " ", then for each value create one int. We are also using [a[i][j] * b[j][i] for j in range(0,n)] to get the resultant row in a single line.
diff --git a/en-US/file.xml b/en-US/file.xml
index aafcf05..e934866 100644
--- a/en-US/file.xml
+++ b/en-US/file.xml
@@ -20,28 +20,21 @@
The default mode is read only, ie if you do not provide any mode it will open the file as read only. Let us open a file
-
->> f = open("love.txt")
+>> f = open("love.txt")
>>> f
-
-]]>
+]]>
-
+
Closing a file
After opening a file one should always close the opened file. We use method close() for this.
-
->> f = open("love.txt")
+>> f = open("love.txt")
>>> f
->>> f.close()
-
-]]>
+>>> f.close()]]>
Important
@@ -63,117 +56,91 @@ Because
To read the whole file at once use the read() method.
-
->> f = open("sample.txt")
+>> f = open("sample.txt")
>>> f.read()
-'I love Python\nPradeepto loves KDE\nSankarshan loves Openoffice\n'
-]]>
+'I love Python\nPradeepto loves KDE\nSankarshan loves Openoffice\n']]>
If you call read() again it will return empty string as it already read the whole file. readline() can help you to read one line each time from the file.
-
->> f = open("sample.txt")
+>> f = open("sample.txt")
>>> f.readline()
'I love Python\n'
>>> f.readline()
-'Pradeepto loves KDE\n'
-]]>
+'Pradeepto loves KDE\n']]>
To read all the all the lines in a list we use readlines() method.
-
->> f = open("sample.txt")
+>> f = open("sample.txt")
>>> f.readlines()
-['I love Python\n', 'Pradeepto loves KDE\n', 'Sankarshan loves Openoffice\n']
-]]>
+['I love Python\n', 'Pradeepto loves KDE\n', 'Sankarshan loves Openoffice\n']]]>
You can even loop through the lines in a file object.
-
->> f = open("sample.txt")
+>> f = open("sample.txt")
>>> for x in f:
... print x,
...
I love Python
Pradeepto loves KDE
-Sankarshan loves Openoffice
-]]>
+Sankarshan loves Openoffice]]>
Let us write a program which will take the file name as the input from the user and show the content of the file in the console.
-
-
-
+f.close()]]>
+
In the last line you can see that we closed the file object with the help of close() method.
The output
-
-
+Sankarshan loves Openoffice]]>
-
+
Writing in a file
Let us open a file then we will write some random text into it by using the write() method.
-
->> f = open("ircnicks.txt", 'w')
+>> f = open("ircnicks.txt", 'w')
>>> f.write('powerpork\n')
>>> f.write('indrag\n')
>>> f.write('mishti\n')
>>> f.write('sm|CPU')
->>> f.close()
-]]>
+>>> f.close()]]>
Now read the file we just created
-
->> f = open('ircnicks.txt')
+>> f = open('ircnicks.txt')
>>> s = f.read()
>>> print s
powerpork
indrag
mishti
-sm|CPU
-]]>
+sm|CPU]]>
-
+
copyfile.py
In this example we will copy a given file to another file.
-
-
-
+f2.close()]]>
+
You can see we used a new module here sys. sys.argv contains all command line parameters. Remember cp command in shell, after cp we type first the file to be copied and then the new file name.
The first value in sys.argv is the name of the command itself.
-
-
-
+ print i, x]]>
+
The output
-
-
+2 there]]>
Here we used a new function enumerate(iterableobject), which returns the index number and the value from the iterable object.
-
+
Random seeking in a file
@@ -241,9 +201,7 @@ Note that not all file objects are speakable.
Let us see one example
-
->> f = open('tempfile', 'w')
+>> f = open('tempfile', 'w')
>>> f.write('0123456789abcdef')
>>> f.close()
>>> f = open('tempfile')
@@ -256,8 +214,7 @@ Note that not all file objects are speakable.
'5'
>>> f.seek(-3, 2) # goto 3rd byte from the end
>>> f.read() #Read till the end of the file
-'def'
-]]>
+'def']]>
diff --git a/en-US/functions.xml b/en-US/functions.xml
index 57dbddc..02d2f8a 100644
--- a/en-US/functions.xml
+++ b/en-US/functions.xml
@@ -5,45 +5,34 @@
Functions
- Reusing the same code is required many times within a same program. Functions help us to do so. We write the things we have to do repeatedly in a function then call it where ever required. We already saw build in functions like len(), divmod().
+ Reusing the same code is required many times within a same program. Functions help us to do so. We write the things we have to do repeatedly in a function then call it where ever required. We already saw build in functions like len(), divmod().
Defining a function
We use def keyword to define a function. general syntax is like
-
-
+ statement2]]>
Let us write a function which will take two integers as input and then return the sum.
-
->> def sum(a, b):
-... return a + b
-]]>
+>> def sum(a, b):
+... return a + b]]>
In the second line with the return keyword, we are sending back the value of a + b to the caller. You must call it like
-
->> res = sum(234234, 34453546464)
+>> res = sum(234234, 34453546464)
>>> res
-34453780698L
-]]>
+34453780698L]]>
Remember the palindrome program we wrote in the last chapter. Let us write a function which will check if a given string is palindrome or not, then return True or False.
-
-
-
+ print "Oh no, not a palindrome"]]>
+
Now run the code :)
-
+
Local and global variables
To understand local and global variables we will go through two examples.
-
-
-
+print "After the function call ", a]]>
+
The output
-
-
+After the function call 9]]>
First we are assigning 9 to a, then calling change function, inside of that we are assigning 90 to a and printing a. After the function call we are again printing the value of a. When we are writing a = 90 inside the function, it is actually creating a new variable called a, which is only available inside the function and will be destroyed after the function finished. So though the name is same for the variable a but they are different in and out side of the function.
-
-
-
+print "After the function call ", a]]>
+
Here by using global keyword we are telling that a is globally defined, so when we are changing a's value inside the function it is actually changing for the a outside of the function also.
-
+
Default argument value
- In a function variables may have default argument values, that means if we don't give any value for that particular variable it will assigned automatically.
+ In a function variables may have default argument values, that means if we don't give any value for that particular variable it will assigned automatically.
-
->> def test(a , b = -99):
+>> def test(a , b = -99):
... if a > b:
... return True
... else:
@@ -130,13 +108,10 @@ print "After the function call ", a
In the above example we have written b = -99 in the function parameter list. That means of no value for b is given then b's value is -99. This is a very simple example of default arguments. You can test the code by
-
->> test(12, 23)
+>> test(12, 23)
False
>>> test(12)
-True
-]]>
+True]]>
Important
@@ -147,9 +122,7 @@ True
Also remember that default value is evaluated only once, so if you have any mutable object like list it will make a difference. See the next example
-
->> def f(a, data=[]):
+>> def f(a, data=[]):
... data.append(a)
... return data
...
@@ -158,16 +131,13 @@ True
>>> print f(2)
[1, 2]
>>> print f(3)
-[1, 2, 3]
-]]>
+[1, 2, 3]]]>
-
+
Keyword arguments
-
->> def func(a, b=5, c=10):
+>> def func(a, b=5, c=10):
... print 'a is', a, 'and b is', b, 'and c is', c
...
>>> func(12, 24)
@@ -175,20 +145,16 @@ a is 12 and b is 24 and c is 10
>>> func(12, c = 24)
a is 12 and b is 5 and c is 24
>>> func(b=12, c = 24, a = -1)
-a is -1 and b is 12 and c is 24
-]]>
+a is -1 and b is 12 and c is 24]]>
In the above example you can see we are calling the function with variable names, like func(12, c = 24), by that we are assigning 24 to c and b is getting its default value. Also remember that you can not have without keyword based argument after a keyword based argument. like
-
->> def func(a, b=13, v):
+>> def func(a, b=13, v):
... print a, b, v
...
File "", line 1
-SyntaxError: non-default argument follows default argument
-]]>
+SyntaxError: non-default argument follows default argument]]>
diff --git a/en-US/ifelse.xml b/en-US/ifelse.xml
index 2db2373..9032416 100644
--- a/en-US/ifelse.xml
+++ b/en-US/ifelse.xml
@@ -12,66 +12,49 @@
The syntax looks like
-
-
+
If the value of expression is true (anything other than zero), do the what is written below under indentation. Please remember to give proper indentation, all the lines indented will be evaluated on the True value of the expression. One simple example is to take some number as input and check if the number is less than 100 or not.
-
-
-
+ print "The number is less than 100"]]>
+
Then we run it
-
-
+The number is less than 100]]>
-
+
Else statement
- Now in the above example we want to print "Greater than" if the number is greater than 100. For that we have to use the else statement. This works when the ifstatement is not fulfilled.
+ Now in the above example we want to print "Greater than" if the number is greater than 100. For that we have to use the else statement. This works when the ifstatement is not fulfilled.
-
-
-
+ print "The number is greater than 100"]]>
+
The output
-
-
+The number is greater than 100]]>
Another very basic example
-
->> x = int(raw_input("Please enter an integer: "))
+>> x = int(raw_input("Please enter an integer: "))
>>> if x < 0:
... x = 0
... print 'Negative changed to zero'
@@ -80,8 +63,7 @@ The number is greater than 100
... elif x == 1:
... print 'Single'
... else:
-... print 'More'
-]]>
+... print 'More']]>
diff --git a/en-US/looping.xml b/en-US/looping.xml
index 0aa84ae..aa61504 100644
--- a/en-US/looping.xml
+++ b/en-US/looping.xml
@@ -13,19 +13,14 @@
The syntax for while statement is like
-
-
+ statement2]]>
The code we want to reuse must be indented properly under the while statement. They will be executed if the condition is true. Again like in if-else statement any non zero value is true. Let us write a simple code to print numbers 0 to 10
-
->> n = 0
+>> n = 0
>>> while n < 11:
... print n
... n += 1
@@ -40,8 +35,7 @@ while condition:
7
8
9
-10
-]]>
+10]]>
In the first line we are setting n = 0, then in the while statement the condition is n 11 , that means what ever line indented below that will execute until n becomes same or greater than 11. Inside the loop we are just printing the value of n and then increasing it by one.
@@ -53,21 +47,16 @@ while condition:
Let us try to solve Fibonacci series. In this series we get the next number by adding the previous two numbers. So the series looks like 1,1,2,3,5,8,13 .......
-
-
-
+ a, b = b, a + b]]>
+
The output
-
-
+89]]>
In the first line of the code we are initializing a and b, then looping while b's value is less than 100. Inside the loop first we are printing the value of b and then in the next line putting the value of b to a and a + b to b in the same line.
@@ -87,33 +75,26 @@ while b < 100:
If you put a trailing comma in the print statement , then it will print in the same line
-
-
-
+ a, b = b, a + b]]>
+
The output
-
-
+
-
+
Power Series
Let us write a program to evaluate the power series. The series looks like e**x =1+x+x**2/2! +x**3/3! +....+ x**n/n! where
-
-
-
+print "No of Times= %d and Sum= %f" % (n, sum)]]>
+
The output
-
-
+No of Times= 7 and Sum= 1.648720]]>
- In this program we introduced a new keyword called break. What break does is stop the innermost loop. In this example we are using break under the if statement
+ In this program we introduced a new keyword called break. What break does is stop the innermost loop. In this example we are using break under the if statement
-
-
+
This means if the value of term is less than 0.0001 then get out of the loop.
@@ -159,9 +133,7 @@ if term < 0.0001:
In this example we are going to print the multiplication table up to 10.
-
-
-
+print "-" * 50]]>
+
The output
-
-
+--------------------------------------------------]]>
Here we used one while loop inside another loop, this is known as nested looping. You can also see one interesting statement here
-
-
+
In a print statement if we multiply the string with an integer n , the string will be printed nmany times. Some examples
-
->> print "*" * 10
+>> print "*" * 10
**********
>>> print "#" * 20
####################
>>> print "--" * 20
----------------------------------------
>>> print "-" * 40
-----------------------------------------
-]]>
+----------------------------------------]]>
@@ -223,104 +185,78 @@ print "-" * 50
Here are some examples which you can find very often in college lab reports
Design 1
-
-= 0:
x = "*" * n
print x
- n -= 1
-]]>
-
+ n -= 1]]>
+
The output
-
-
+*]]>
Design 2
-
-
-
+ i += 1]]>
+
The output
-
-
+*****]]>
Design 3
-
-= 0:
x = "*" * n
y = " " * (row - n)
print y + x
- n -= 1
-]]>
-
+ n -= 1]]>
+
The output
-
-
+ *]]>
Lists
- We are going to learn a data structure called list before we go ahead to learn more on looping. Lists an be written as a list of comma-separated values (items) between square brackets.
+ We are going to learn a data structure called list before we go ahead to learn more on looping. Lists an be written as a list of comma-separated values (items) between square brackets.
-
->> a = [ 1 , 342, 2233423, 'India', 'Fedora']
+>> a = [ 1 , 342, 2233423, 'India', 'Fedora']
>>> a
-[1, 342, 2233423, 'India', 'Fedora']
-]]>
+[1, 342, 2233423, 'India', 'Fedora']]]>
Lists can keep any other data inside it. It works as a sequence too, that means
-
->> a[0]
+>> a[0]
1
>>> a[4]
-'Fedora'
-]]>
+'Fedora']]>
You can even slice it into different pieces, examples are given below
-
->> a[4]
+>> a[4]
'Fedora'
>>> a[-1]
'Fedora'
@@ -333,25 +269,18 @@ Enter the number of rows: 5
>>> a[:-2]
[1, 342, 2233423]
>>> a[0::2]
-[1, 2233423, 'Fedora']
-]]>
+[1, 2233423, 'Fedora']]]>
In the last example we used two :(s) , the last value inside the third brackets indicates step. s[i:j:k] means slice of s from i to j with step k.
To check if any value exists within the list or not you can do
-
->> a = ['Fedora', 'is', 'cool']
+>> a = ['Fedora', 'is', 'cool']
>>> 'cool' in a
True
>>> 'Linux' in a
-False
-]]>
+False]]>
That means we can use the above statement as if clause expression. The built-in function len() can tell the length of a list.
-
->> len(a)
-3
-]]>
+>> len(a)
+3]]>
@@ -359,20 +288,16 @@ False
There is another to loop by using for statement. In python the for statement is different from the way it works in C. Here for statement iterates over the items of any sequence (a list or a string). Example given below
-
->> a = ['Fedora', 'is', 'powerfull']
+>> a = ['Fedora', 'is', 'powerfull']
>>> for x in a:
... print x,
...
-Fedora is powerfull
-]]>
+Fedora is powerfull]]>
We can also do things like
-
->>> a = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
+>> a = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
>>> for x in a[::2]:
... print x
...
@@ -380,7 +305,7 @@ Fedora is powerfull
3
5
7
-9
+9]]>
@@ -389,9 +314,7 @@ Fedora is powerfull
range() is a buitin function. From the help document
-
- list of integers
Return a list containing an arithmetic progression of integers.
range(i, j) returns [i, i+1, i+2, ..., j-1]; start (!) defaults to 0.
@@ -403,9 +326,7 @@ range(...)
Now if you want to see this help message on your system type help(range) in the python interpreter. help(s) will return help message on the object s. Examples of range function
-
->> range(1,5)
+>> range(1,5)
[1, 2, 3, 4]
>>> range(1,15,3)
[1, 4, 7, 10, 13]
@@ -420,9 +341,7 @@ range(...)
Just like break we have another statement, continue, which skips the execution of the code after itself and goes back to the start of the loop. That means it will help you to skip a part of the loop. In the below example we will ask the user to input an integer, if the input is negative then we will ask again, if positive then we will square the number. To get out of the infinite loop user must input 0.
-
-
-
+print "Goodbye"]]>
+
The output
-
-[kd@kdlappy book]$ ./continue.py
+
-
+
@@ -454,9 +371,7 @@ Goodbye
We can have an optional else statement after any loop. It will be executed after the loop unless a break statement stopped the loop.
-
->> for i in range(0,5):
+>> for i in range(0,5):
... print i
... else:
... print "Bye bye"
@@ -466,8 +381,7 @@ Goodbye
2
3
4
-Bye bye
-]]>
+Bye bye]]>
We will see more example of break and continue later in the book.
@@ -478,9 +392,7 @@ Bye bye
This is a very simple game of sticks. There are 21 sticks, first the user picks number of sticks between 1-4, then the computer picks sticks(1-4). Who ever will pick the last stick will loose. Can you find out the case when the user will win ?
-
-
-
+ sticks -= 5]]>
+
diff --git a/en-US/modules.xml b/en-US/modules.xml
index b7ea7d8..c56ecbc 100644
--- a/en-US/modules.xml
+++ b/en-US/modules.xml
@@ -161,7 +161,7 @@ help> modules
>> os.getcwd()
-'/home/kdas'
+'/home/kushal'
>>> os.chdir('/tmp')
>>> os.getcwd()
'/tmp'
diff --git a/publican.cfg b/publican.cfg
index 312cfcc..4370dd0 100644
--- a/publican.cfg
+++ b/publican.cfg
@@ -3,5 +3,5 @@
debug: 1
xml_lang: "en-US"
-brand: fedora
+brand: common