# Introduction to Python Programming/Installing Python

'Installing version of Python'
* Download the latest Python Windows installer by going to http://www.python.org/ftp/python/ and selecting the highest version number listed, then downloading the .exe installer.
* Double-click the installer, Python-2.xxx.yyy.exe. The name will depend on the version of Python available when you read this.
* Make sure that you have the administrative rights on the machine that you are working on.
* Step through the installer program.
* Some of the features can be removed from the installation in case you do not have enough space on your hard disk.
* Python will be installed with all the proper files and extensions.
* After the installation is complete, close the installer and select Start->Programs->Python 2.7->IDLE (Python GUI). You'll see something like the following, which is a sample shot from my machine:
Python 2.7.11 (v2.7.11:6d1b6a68f775, Dec 5 2015, 20:32:19) [MSC v.1500 32 bit (Intel)] on win32
' The Interactive Shell'
Method 1:
Figure 2.
Figure 3.
Method 2:
Click on Start-> All Programs->Python2.7->Python IDLE and you’ll see the following shell interpreter as shown in
Figure. 4.
Apparently, there are users who use the Python shell interpreter like a calculator, but I still stick my own calculator on my local Windows machine.
Example 1. First Steps in the Interactive Shell
Welcome to the Python party! Lets Python like we have never Python”ed before.
Kick starting with Python
There is another way to achieve printing “Hello World” like shown in the earlier sections. Store the value “Hello World” in a variable and then print the variable. The output of the print statement are followed by the outputs that they provide just below them
Printing variables
The above print statements focused on printing a single variable. However, a combination of different variables can be printed using a same single print command. >>> x=5 >>> y=7 >>> print x 5 >>> print y 7 >>> print x,y 5 7 >>> print (x,y) (5, 7) Before printing integer variables, they have to be converted to string type using the str when printing along with string variables.
>>> print str(x) + str(y) 57 >>> print str(x) + " " + str(y) 5 7 >>> print x+7 12 >>> print x+y 12 >>> print (x+y) 12 >>> print "the sum of %d and %d is %d" %(x,y,x+y) the sum of 5 and 7 is 12
Getting text inputs
Obtaining input from the interpreter into the shell is done using the input command available. The syntax and the following statements highlight the use of input commands. Strings inputs have to be enclosed within quotes. Errors are highlighted in red.
>>> input("what is the number") what is the number3 3
>>> input("whats my name!:") whats my name!:Some Traceback (most recent call last):
NameError: name 'Some' is not defined
>>> input("whats my name!:") whats my name!:"New Name" 'New Name'
>>> name=input("whats my name!:") whats my name!:"New Name"
>>> print name New Name
>>> print (name) New Name >>> print "My name is " + name My name is New Name
Python typecasts the variable based on the input you provide the Python interpreter.
>>> print "My name is " + name My name is New Name
>>> age=input("whats my name!:") whats my name!:34
>>> print age 34
>>> print type(name) <type 'str'>
>>> print type(age) <type 'int'>
>>> print type(name), type(age) <type 'str'> <type 'int'>
>>> print "The data type of "+ name +" and "+str(age)+"is "+ str(type(name)) + "and " + str(type(age)) The data type of New Name and 34is <type 'str'>and <type 'int'>
However for ease of use, you can specifically instruct the Python interpreter to typecast the input into the type of variable you want to use the variable in. if you don’t specifically provide the typecast, Python interpreter will do the job of typecasting the variable.
>>> x=int(input("enter a integer number")) enter a integer number3
>>> x 3
>>> x=float(input("enter a integer number")) enter a integer number4
>>> print x 4.0
>>> x 4.0
>>> x=str(input("enter a integer number")) enter a integer number4
>>> x '4'
>>> x=input("enter a integer number") enter a integer number5
>>> x 5
>>> print type(x) <type 'int'>
Now that we have a fair idea of the print and the input commands, let’s write a simple Python program that will ask your name, age, location, and your job details and prints the same. On the Python interpreter, I opened a new file and wrote the following piece of code and saved it as file.py.
name=input("Enter your name: ") age=input("Enter a two digit number as age: ") location=input("Enter your current location: ") job=input("Enter your job details: ")
print "Hi There!!! \nMy name is %s,\nMy age is %d,\nI am located at %s and currently working as %s" %(name,age,location,job)
Further, I ran the program on the Python shell and obtained my first output for the same.
Enter your name: "Suzaane" Enter a two digit number as age: 37 Enter your current location: "Buffalo" Enter your job details: "Research Programmer" Hi There!!! My name is Suzaane, My age is 37, I am located at Buffalo and currently working as Research Programmer >>> There you go, you just wrote your first Python program and ran it on the Python interpreter.