Friday, March 25, 2011

Run Python script in Linux

Hello everyone,

Now its time to give it a try for python. Pythons is general-purpose high level programming language. The python's syntax is very clear and human readable.
The interesting fact about python is, It never forces programmer to write a code in OOPS style like java or in structural style like in c. It is all up to programmer how he/she wants to implement it.
Python is influenced by ABC, ALGOL 68, C, C++, Java, Haskell, Pearl etc.
Python can be run on multiple platforms.

Now lets begin with our first program i.e. how to print hello world. For that just go to your terminal
from Applications>>Accessories>>Terminal

step 1. Just type python
it will show you

Python 2.6.6 (r266:84292, Sep 15 2010, 15:52:39)

[GCC 4.4.5] on linux2

Type "help", "copyright", "credits" or "license" for more information.


step 2. This is nothing but your python version installed on the system.

Step 3. Now you are in python mode. Means not at primary prompt. i.e. >>>

step 4. Just write print “hello world” and hit enter. Thats it , yes you are done. It will show you
the output at next line like 'hello world'

1. you can also use python as desktop calculator at go to terminal just type python and at python prompt (which is >>>) just type 5+2 and it will give you the answer.

2. You can also edit bigger python code in your favorite text editor with following command
gedit and hit enter you will see new file open in gedit which is default
text editor for linux.

3. Remember .py is file extention of python files but some times we also uses .pyw, .pyc, .pyo, .pyd

4. If you are python prompt (which is after typing python at primary prompt) you can terminate
any operation by pressing the CTRL+C

5. If you want to terminate everything from the terminal and go back to the primary prompt
then simply type CTRL+D

6. As python is influenced from C language so you can write the same code except curly
braces ( {} ) are not welcome here instead use proper indentation.

7. Python also requires proper indentation while programming if not it will generate
indentation error
like e.g.

if a==2:
print “a is equal to two”

the above code will generate indentation error so right way is to do is put a tab of space before
print statement
Right way is



... print "a is equal to two"

... else:

... print "a is not equal to two"

now the output will be

a is equal to two

If you want the beginners python pdf you can get it from here.

So bye for now and feel free to comment on any of my post.

Enjoy & be open.
long live linux

Saturday, March 19, 2011

Run C programs in Linux

Hello friends,
Before we proceed I would like to thanks MR.Richard Stallman (founder of GNU project) for free software movement.
I will now demonstrate you the steps that you can follow to run C PROGRAMS on any linux distribution like ubuntu,Linux 10 mint,OPEN SUSE,fedora etc.

You might have used microsoft c,Turbo c or Borland c compiler but, GNU compiler is little different from all of it as it compiles c programs faster and produces the output at the terminal.

You can also create, compile and run your any C PROGRAMS. All you have to do is get any linux distribution installed on your computer machine.

1)To create your c program go to your Terminal from Applications >> Accessories >> Terminal
2)Just Type gedit hello.c &
Now here gedit is command to open Linux's default text editor afterwards hello.c is your filename. Now just hit enter.
3)Now You will see one brand new file open next to your eyes. Now just type any your first c program or copy paste following code:

#include< stdio.h >
int a,b,c;
printf("Enter two number for an addition\n");
printf("Total of two number is %d\n",c);

4)before main() I have included standard input output files so that printf scanf function works
(note: please remove white spaces which is before the stdio.h and after stdio.h word because right now google is treating it as html tag )

5)Now Save the file.
6)Go back to terminal just type gcc -o hello hello.c
and hit enter.
7)Now you can type ./hello and hit the enter and see the output.

This is how you can run any c programs in linux operating system. At the next tutorial we will see how to run python programs in linux operating system.

so bye for now,

Enjoy & be open.
long live linux