Archive for the ‘Python’ Category

Chapter 11 – Python For Loop

 
Step 1
 
Open any text editor (gedit,pico,vi,nano) then enter the following python script and save the file with .py extension.
 
#!/usr/bin/python
#Author : Jijo K Jose
 
print "\n————————————\nChapter 11 – For Loop \n————————————\n"
 
for i in range(10,25,2):
  print i
 
print "\n————————————–\n"
 
#END

Read more »

Chapter 10 – Python Command Line Arguments

 
Step 1
 
Open any text editor (gedit,pico,vi,nano) then enter the following python script and save the file with .py extension.
 
#!/usr/bin/python
#Author : Jijo K Jose
 
print "\n————————————\nChapter 10 – Command Line Parameters \n————————————\n"
 
import sys
 
if(len(sys.argv) < 3):
 print "You should enter 2 argument"
elif(len(sys.argv) >=3):
 print "You entered %d argument " %(len(sys.argv)-1)
 print "The sys.argv values are : ", sys.argv
 print "sys.argv values in separte lines are…."
 for i in sys.argv:
  print i
 
print "\n————————————–\n"
 
#END

Read more »

Chapter 9 – Python Conditionals

 
Step 1
 
Open any text editor (gedit,pico,vi,nano) then enter the following python script and save the file with .py extension.
 
#!/usr/bin/python
#Author : Jijo K Jose
 
print "\n————————————\nChapter 9 – Conditionals \n————————————\n"
 
a = input("Enter integer A : ")
b = input("Enter integer B : ")
if a == b:
 print "A and B are same"
elif a < b:
 print "B is larger"
else:
 print "A is larger"
 
print "\n————————————–\n"
 
#END

Read more »