0% found this document useful (0 votes)
212 views104 pages

Practical File of Programming in Data Structures

This document is a practical file submitted by Harshpreet Kaur to partially fulfill requirements for a B.Tech degree in Computer Science and Engineering. It contains 26 programs written in Python covering topics such as printing biodata, checking number types, calculating sums, and using recursion. The file introduces Python and discusses its history, development process, and getting started with the interpreter.

Uploaded by

Girja Sharma
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
212 views104 pages

Practical File of Programming in Data Structures

This document is a practical file submitted by Harshpreet Kaur to partially fulfill requirements for a B.Tech degree in Computer Science and Engineering. It contains 26 programs written in Python covering topics such as printing biodata, checking number types, calculating sums, and using recursion. The file introduces Python and discusses its history, development process, and getting started with the interpreter.

Uploaded by

Girja Sharma
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 104

PRACTICAL FILE OF PROGRAMMING IN

DATA STRUCTURES
Submitted in partial fulfilment of the requirements for the degree
B.Tech(Computer Science and Engineering)

Submitted to
MR. INDERPAL SINGH
Submitted by
HARSHPREET KAUR
Roll No:2016CSA1413

DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING


GURU NANAK DEV UNIVERSITY REGIONAL CAMPUS
JALANDHAR(INDIA)
S.No Contents Page Remark
no
1. Introduction to python 3-7
2. Windows installation 8-27
3. Write a program to represent your biodata 28
4. Write a program to print grades of students 29
5. Write a program to check whether a no is odd or even 30
6. Write a program to check whether a no is prime or not 31
7. Write a program to print table of a number 32
8. Write a program to check whether a no is positive,negative or 33
zero
9. Write a program to find square root of a number 34
10. Write a program to find area of triangle 35
11. Write a program to find greater of three numbers 36
12. Write a program to apply membership operator in and not in 37
13. Write a program to apply identity operator is and is not 38
14. Write a program to print prime numbers between 0 &100 39
15. Write a program to find sum of natural numbers using 40
recursion
16. Write a program sum of numbers until zero 41
17. Write a program to determine sum of number 42
18. write a program to determine reverse of a number 43
19. Write a program to determine factorial of a number 44
20. Write a program to determine a no in different languages 45
21. Write a program to print fibonicci series 46
22. Write a program to print fibonicci series using recursion 47
23. Write a program to check whether numbers in a listis divisible 48
by two or not using filter
24. Write a program to print square of a number using map 49
anonymous function
25. Write a program to make a calculator by creating modules 50-51
26. Write a program to print table of a number using raised 52
power as a variable

2
INTRODUCTION TO PYTHON

Python is a powerful modern computer programming language. It bears some similarities to


Fortran, on software .one of the earliest programming languages,but it is much more
powerful than Fortran python allows u to use variables without declaring them(i.e .,it
determines types implicitly),and it relies on indentations a control structure u are not forced
to define classes in python(unlike java)but u are free to do so Python was developed by
Guido Van Rossum ,and it is free software. Free as in "free beer", in that you can obtain
python without spending any money. But python is also free in other important ways, for
example you are free to copy it as many times as you like, and free to study the source code,
and make changes to it There is worldwide movement behind the idea of free software,
initiated in 1983 by Richard Stallman.

Python is a good choice for mathematical calculation ,since we can write code quickly, test it
easily, and its syntax is similar to the way mathematical ideas are expressed in the
mathematical literature .By learning python u will also be learning a major tool used by many
web developers

INSTALLATION AND DOCUMENTATION:


Version by visiting the python homepage If u use Mac OS X or linux ,then python should
already be installed on ur computer by default .If not ,u can download the latest at
http://www.python.org

HISTORY
The history of the Python programming language dates back to the late 1980s.

Python was conceived in the late 1980sand its implementation was started in December 1989
by Guido van Rossum at CWI in the Netherlands as a successor to the ABC programming
language capable of exception handling and interfacing with the Amoeba operating system.
Python was named for the BBC TV show Monty Python's Flying Circus. Van Rossum is
Python's principal author, and his continuing central role in deciding the direction of Python
is reflected in the title given to him by the Python community, Benevolent Dictator for Life
(BDFL).

Python 2.0 was released on October 16, 2000, with many major new features, including a
cycle-detecting garbage collector (in addition to reference counting) for memory
management and support for Unicode. However, the most important change was to the
development process itself, with a shift to a more transparent and community-backed process.
Python 3.0, a major, backwards-incompatible release, was released on December 3, 2008
after a long period of testing. Many of its major features have also been backported to the
backwardscompatible Python 2.6 and 2.7.

First publication
In February 1991, Van Rossum published the code (labeled version 0.9.0) to alt sources.
Already present at this stage in development were classes with inheritance exception
handling, functions, and the core datatypes of list, dict, str and so on. Also in this initial
release was a module system borrowed from Modula-3.Van Rossum describes the module as
"one of Python's major programming units". Python's exception model also resembles
Modula-3's, with the addition of an else clause.In 1994 comp .lang. python the primary
discussion forum for Python, was formed, marking a milestone in the growth of Python's
userbase.

Version release dates

Release dates for the major and minor versions:

• Python 1.0 - January 1994 o Python


1.5 - December 31, 1997 o Python
1.6 - September 5, 2000
• Python 2.0 - October 16, 2000 o
Python 2.1 - April 17, 2001 o
Python 2.2 - December 21, 2001
o Python 2.3 - July 29, 2003 o
Python 2.4 - November 30, 2004
o Python 2.5 - September 19,
2006 o Python 2.6 - October 1, 2008 o
Python 2.7 - July 3, 2010
• Python 3.0 - December 3, 2008 o
Python 3.1 - June 27, 2009 o
Python 3.2 - February 20, 2011
o Python 3.3 - September 29,
2012 o Python 3.4 - March 16, 2014 o
Python 3.5 - September 13,
2015 o Python 3.6 - December 23, 2016

Version 1.0 (1994)

Python reached version 1.0 in January 1994. The major new features included in this release
were the functional programming tools lambda, mapfilter and reduce. Van Rossum stated that
"Python acquired lambda, reduce(), filter() and map(), courtesy of a Lisp hacker who missed
them and submitted working patches"

The last version released while Van Rossum was at CWI was Python 1.2. In 1995, Van
Rossum continued his work on Python at the Corporation for National Research Initiatives
(CNRI) in Reston, Virginia whence he released several versions.

By version 1.4, Python had acquired several new features. Notable among these are the
Modula-3 inspired keyword arguments(which are also similar to Common Lisp's keyword
arguments) and built-in support for complex numbers. Also included is a basic form of data
hiding by name mangling, though this is easily bypassed.

4
Python served a central role in this: because of its focus on clean syntax, it was already
suitable, and CP4E's goals bore similarities to its predecessor, ABC. The project was funded
by DARPA. As of 2007, the CP4E project is inactive, and while Python attempts to be easily
learnable and not too arcane in its syntax and semantics, reaching out to non-programmers is
not an active concern.

GETTING STARTED

1.Running python as a calculator The easiest way to get started is to run python as an
interpreter, which behaves similar to the way one would use a calculator .In the interpreter
,you type a command, and python produces the answer .then u type another command ,which
again produces an answer ,and so on .In OS X or Linux, to start the python interpreter is as
simple as typing the command python on the command line in a terminal shell .In windows
,assuming that python has already been installed, you need to find python on the appropriate
menu. Windows users can choose to run python in a command shell where it will behave
very similarly to Linux or OS X.

For all three operating systems there is also an integrated development environment for
python named IDLE. If interested,you may download and install this on your computer .Once
python start running in interpreter mode ,using IDLE or a command shell ,it produces a
prompt ,which waits for ur input .for example ,this is what i get when I start python in my
command shell or my Linux box.
2.QUITTING THE INTERPRETER
In a terminal you can quit python session by CTRL-D. In IDLE you can also quit from the
menu.

If the interpreter gets struck in an infinite loop, you can quit the current execution by CTRL-
C.

3. Loading commands from the library:


Python has a very extensive library of commands, documented in the Python Library
Reference Manual. These commands are organised into modules.

4. Defining functions:
It is possible and very useful to define our own functions in python. Generally speaking, if
you need to do a calculation only once ,then use the interpreter. But when u or others have
need to perform certain type of calculation many times then define a function. For a simple
example, the compound command >>>def f(x):

... return x**x


...

defines the squaring function f(x)=x^2,a popular example used in elementary math courses In
the definition ,the first line is the function header where the name, of the function is specified.
subsequent lines give the body of the function, where the output value is calculated. Note that
final step is to return the answer; without it we would never see any results .continuing the
example ,we can use the function to calculate the square of any given input :

>>>f(2)

>>> f(2.5)

6.25 5.

FILES:
Python allows us to store our code in files(also called modules).This is very useful for more
serious to change one mistake .In doing this ,we are essentially defining our own modules
,just like the modules defined already in the python library

PYTHON FEATURES

Python's features include:

• Easy-to-learn: Python has few keywords, simple structure, and a clearly defined
syntax. This allows the student to pick up the language quickly.
• Easy-to-read: Python code is more clearly defined and visible to the eyes.
• Easy-to-maintain: Python's source code is fairly easy-to-maintain.
• A broad standard library: Python's bulk of the library is very portable and
crossplatform compatible on UNIX, Windows, and Macintosh.
• Interactive Mode:Python has support for an interactive mode which allows
interactive testing and debugging of snippets of code.
• Portable: Python can run on a wide variety of hardware platforms and has the same
interface on all platforms.
• Extendable: You can add low-level modules to the Python interpreter. These
modules enable programmers to add to or customize their tools to be more efficient.
• Databases: Python provides interfaces to all major commercial databases.
• GUI Programming: Python supports GUI applications that can be created and ported
to many system calls, libraries and windows systems, such as Windows MFC,
Macintosh, and the X Window system of Unix.
• Scalable: Python provides a better structure and support for large programs than shell
scripting.
Apart from the above-mentioned features, Python has a big list of good features, few are
listed below:

• It supports functional and structured programming methods as well as OOP.


• It can be used as a scripting language or can be compiled to byte-code for building
large applications.
• It provides very high-level dynamic data types and supports dynamic type checking.
• IT supports automatic garbage collection.

6
• It can be easily integrated with C, C++, COM, ActiveX, CORBA, and Java.

STEPS FOR INSTALLATION OF


WINDOW 8
Select your language. Once the Windows 8 installation begins, you will be prompted to
select a language, time and currency format, and keyboard layout. Once you select these,
click Next.
STEP 2:
Click Install Now. This will begin the installation process. The other option is for repairing
an existing Windows installation.

8
STEP 3:
Enter your product key. This is the 25 character key that came with your purchased copy of
Windows 8. It may be located on a sticker on your computer or underneath your laptop.

• You do not need to enter the dashes between the groups of characters.

• This is not an optional step. Previous versions of Windows allowed you to register
your product up to 60 days after installing. You must now enter the key before
installation begins.

10
STEP 4:
Accept the license agreement. Once you have read the agreement, check the box signifying
that you accept the agreement and click next.

11
STEP 5:
Click Custom Install. You will have two options to install windows. Picking Custom will
allow you to do a complete installation of Windows 8. Selecting upgrade can cause
performance problems in the long run. It is highly recommended that you do a clean Custom
Install.

12
STEP 6:
Delete the partition. A window will open asking where you would like to install Windows 8.
In order to perform a clean install, you need to delete the old partition and start with a clean
slate. Click “Drive options (advanced).” This will give you the ability to delete and create
partitions.

• Select the partition of your existing operating system and click the Delete button.

13
• If you are installing an operating system for the first time on this hard drive, then
there will be no partitions to delete.

14
• If your hard drive has multiple partitions, be sure to delete the correct one. Any data
on a deleted partition is lost for good.
• Confirm the deletion process.

15
16
STEP 7:
Select the Unallocated Space and click Next. There is no need to create a partition before
you install Windows 8, this is done automatically.

17
STEP 8:
Wait while Windows installs files. The percentage next to Expanding Windows files will
steadily increase. This part of the process can take up to 30 minutes.

• Windows will automatically restart your computer when finished.

18
19
STEP 9:
Wait while Windows gathers information. After the computer reboots, you will see the
Windows 8 logo. Beneath it will be the text “Getting devices ready” followed by a percentage.
Windows is collecting information on the hardware installed in your computer.

• When this is done, the text will change to “Getting ready”.


• Your computer will restart one more time.

20
STEP 10:
Personalize your Windows 8.Once the computer finishes rebooting, you will be asked to pick
the color scheme for your installation of Windows 8.

• You can change the color at any time in the Windows 8 settings.

21
STEP 11:
Enter a computer name. This is the name that the computer displays on the network. Any
other device on the network will see your computer listed with this name.
STEP 12:
Choose your wireless network. If you have a wireless-enable computer or device, you will
see a menu asking you to choose a network. If you haven’t installed the driver for your
wireless card yet, this step will automatically be skipped.

22
Step 13
Choose your settings.The most common option is Express Settings, which will enable
automatic updates, Windows Defender, and error reporting to Microsoft, among other things.

• If you’d rather set these yourself, choose Customize instead of Express Settings.

23
24
STEP 14:
Create an account. To log in to Windows, you will need an account. Microsoft recommends
using a Microsoft account, so that you can make purchases in the Windows store. If you
don’t have a Microsoft account, entering a valid email address will create one for free.

• If you don’t have an email address, click the “Sign up for a new email address” link to
create one. This requires an internet connection.

25
• If you’d rather sign in the old way, without using a Microsoft account, click the
bottom link. This will create a login similar to previous versions of Windows.

26
27
Program:-1
Write A program to represent your bio data
a=input("enter your name")

b=int(input("enter your roll no"))

c=input("enter your stream")

d=input("enter your address")

print("name:", a)

print("roll no:", b)

print("stream:", c)

print("address:", d)

28
PROGRAM-2

Write A Program to print grades of the students

a=int(input("enter value of english"))

b=int(input("enter value of math"))

c=int(input("enter value of computer")) d=(a+b+c)/3

if(d>90):

print("enter grade a") elif(90>d>80):

print("enter grade b") else:

print("enter grade c")

PROGRAM-3

WRITE A PROGRAM TO CHECK WHETHER A NUMBER IS ODD OR


EVEN
a=int(input("enter your number")); if(a%2==0):

29
print("no is even") else:

print("no is odd")

PROGRAM 4

WRITE A PROGRAM TO CHECK WHETHER A NUMBER IS PRIME


OR NOT

30
a=int(input("enter a number"));

f=0; for i in range(2,a):

if(a%i==0):

f=1;

break;

if(f==1):

print ("Not Prime");

else: print("prime

number")

PROGRAM-5

WRITE A PROGRAM TO PRINT TABLE OF ANY NUMBER


n=30

for i in range(1,20):

print(n,"*",i,"=",(n*i))

31
Program 6

WRITE A PROGRAM TO CHECK A NO IS NEGATIVE, POSITIVE OR


ZERO
num=int(input("enter a number")); if(num>0):

print("number is positive"); elif(num<0):

print("number is negative"); else:

32
print("number is zero"); output:

Program 7

WRITE A PROGRAM TO FIND SQUARE ROOT OF A NUMBER


a=int(input("enter a number")); b=a**0.5;

print(b);

33
Program 8

WRITE A PROGRAM TO FIND AREA OF TRIANGLE


a=int(input("enter a number"));

b=int(input("enter a number"));

c=int(input("eneter a number"));

s=(a+b+c)/2; area=(s*(s-a)*(s-

b)*(s-c)); print(area) output:

34
Program 9

WRITE A PROGRAM TO FIND GREATER OF THREE NUMBERS


a=int(input("enter a number"));

b=int(input("enter a number"));

c=int(input("enter a number"));

if(a>b)and(a>c): print("a is

greater");

elif(b>a)and(b>c):

print("b is greater"); else:

print("c is greater");

35
output:

Program 10

WRITE A PROGRAM TO APPLY MEMBERSHIP OPERATOR IN AND


NOT IN
a=10; b=20;

list=[1,2,3,4,5];

if(a in list):

print("line-1-a is available in the given list"); else:

print("line1-a is not available in the list"); if(b

not in list):

print("line2- b is not available in the list"); else:

print("line2-b is available in the list");

36
Program 11

WRITE A PROGRAM TO APPLY IDENTITY OPERATOR IS AND IS


NOT
a=20; b=20;

if(a is b):

print("line1-a and b have same identity") else:

print("line1-a and b do not have same identity");

b=30;

if(a is b ):

print("line2-a and b have same identity") else:

print("line2-a and b do not have same identity"); output:

37
PROGRAM 12:

WRITE A PROGRAM TO PRINT PRIME NUMBERS BETWEEN 0 TO


100
for a in range(1,100+1):

b=0; for i in

range(1,a+1):

if(a%i==0):

b=b+1; if(b==2):

print(a) output:

38
PROGRAM 13:

WRITE A PROGRAM TO FIND SUM OF NATURAL NUMBERS USING


RECURSION
def recur_sum(n):

if (n<=1):

return n else:

return n+recur_sum(n-1)

num=int(input("enter a number")) if

(num<0):

print("enter a positive number") else:

print("The sum is ",recur_sum(num)) output:

39
PROGRAM 14:

WRITE A PROGRAM TO IMPLEMENT SUM OF NUMBERS UNTIL


ZERO
a=1;

sum=0

while(a!=0): a=int(input("enter

any number")) sum=sum+a

print('total sum is:',sum) output:

40
PROGRAM 15:

WRITE A PROGRAM TO DETERMINE SUM OF A NUMBER


def sum(arg1,arg2):

total=arg1+arg2;

print(total)

sum(10,20) output:

41
PROGRAM 16:

WRITE A PROGRAM TO DETERMINE REVERSE OF A NUMBER


a=1234; reverse=0;

while(a>0):

remainder=a%10;

reverse=(reverse*10)+remainder;

a=a//10; print("the reverse of number

is",reverse) output:

42
PROGRAM 17:

WRITE A PRROGRAM TO DETERMINE FACTORIAL OF A


NUMBER
num=int(input("enter a number"));

factorial=1;O if (num<0):

print("factorial does not exist");

elif(num==0):

print("factorial is 1");

else: for i in

range(1,num+1):

43
factorial=(factorial*i);

print(factorial) output:

PROGRAM 18:

WRITE A PROGRAM TO DETERMINE A NO IN DIFFERENT


LANGUAGES
dec=20

print(bin(dec))

print(hex(dec))

print(oct(dec)) output:

44
PROGRAM 19:

WRITE A PROGRAM TO PRINT FIBONACCI SERIES


num=int(input("enter a number"));

p=0; c=1;

print(p); print(c); for i

in range(1,num+1):

n=(p+c)

45
print(n)

p=c; c=n;

output:

PROGRAM 20:

WRITE A PROGRAM TO PRINT FIBONNICI SERIES USING


RECURSION
def recur_fibo(n):

if(n<=1):

return n else:

return(recur_fibo(n-1)+recur_fibo(n-2))

nterms=int(input("enter a number")) if

(nterms<=0):

print("please enter a positive integer") else:

46
print("fibonnici sequence:")

for i in range(nterms):

print(recur_fibo(i)) output:

PROGRAM 21:

WRITE A PROGRAM TO CHECK WHETHER NUMBERS IN THE


LIST IS DIVISIBLE BY TWO OR NOT USING FILTER

my_list=[12,65,54,39,102,339,221]

result=list(filter(lambda x%2==0),my_list))

print(“numbers divisible by 2 are “,result)

output:

47
PROGRAM 22:

WRITE A PROGRAM TO PRINT SQUARE OF NUMBERS USING


MAP_ANONYMOUS FUNCTION
square = lambda x: x ** 2

print(square(5)) output:

48
PROGRAM 22:

WRITE A PROGRAM TO MAKE A CALCULATOR BY CREATING


MODULES
def add(x, y):

"""This function adds two numbers"""

return x + y

49
def subtract(x, y):

"""This function subtracts two numbers"""

return x - y

def multiply(x, y):

"""This function multiplies two numbers"""

return x * y

def divide(x, y):

"""This function divides two numbers"""

return x / y

# take input from the user

print("Select operation.")

print("1.Add") print("2.Subtract")

print("3.Multiply")

print("4.Divide")

choice = input("Enter choice(1/2/3/4):")

num1 = int(input("Enter first number: ")) num2

= int(input("Enter second number: "))

if choice == '1':

print(num1,"+",num2,"=", add(num1,num2))

elif choice == '2':

50
print(num1,"-",num2,"=", subtract(num1,num2))

elif choice == '3':

print(num1,"*",num2,"=", multiply(num1,num2))

elif choice == '4':

print(num1,"/",num2,"=", divide(num1,num2))

else:

print("Invalid input") output:

PROGRAM 23:

WRITE A PROGRAM TO PRINT TABLE OF A NUMBER USING


RAISED POWER AS A VARIABLE
n=int(input("enter a number")) terms = 10 result

= list(map(lambda x: n ** x, range(terms)))

print("The total terms is:",terms) for i in

range(terms):

print("n raised to power",i,"is",result[i]) output:

51
52
PRACTICAL FILE OF PROGRAMMING IN
PYTHON
Submitted in partial fulfilment of the requirements for the degree
B.Tech(Computer Science and Engineering)
Submitted by
GIRJA
Roll No:2016CSA1411
Submitted to
Ms Babita

DEPARTMENT OF COMPUTER SCIENCE & ENGINEERING


GURU NANAK DEV UNIVERSITY REGIONAL CAMPUS
JALANDHAR(INDIA)
JAN-MAY2017

53
INTRODUCTION TO PYTHON

Python is a powerful modern computer programming language. It bears some similarities to


Fortran, on software .one of the earliest programming languages,but it is much more
powerful than Fortran python allows u to use variables without declaring them(i.e .,it
determines types implicitly),and it relies on indentations a control structure u are not forced
to define classes in python(unlike java)but u are free to do so Python was developed by
Guido Van Rossum ,and it is free software. Free as in "free beer", in that you can obtain
python without spending any money. But python is also free in other important ways, for
example you are free to copy it as many times as you like, and free to study the source code,
and make changes to it There is worldwide movement behind the idea of free software,
initiated in 1983 by Richard Stallman.

Python is a good choice for mathematical calculation ,since we can write code quickly, test it
easily, and its syntax is similar to the way mathematical ideas are expressed in the
mathematical literature .By learning python u will also be learning a major tool used by many
web developers

INSTALLATION AND DOCUMENTATION:


Version by visiting the python homepage If u use Mac OS X or linux ,then python should
already be installed on ur computer by default .If not ,u can download the latest at
http://www.python.org

HISTORY
The history of the Python programming language dates back to the late 1980s.

Python was conceived in the late 1980sand its implementation was started in December 1989
by Guido van Rossum at CWI in the Netherlands as a successor to the ABC programming
language capable of exception handling and interfacing with the Amoeba operating system.
Python was named for the BBC TV show Monty Python's Flying Circus. Van Rossum is
Python's principal author, and his continuing central role in deciding the direction of Python
is reflected in the title given to him by the Python community, Benevolent Dictator for Life
(BDFL).

Python 2.0 was released on October 16, 2000, with many major new features, including a
cycle-detecting garbage collector (in addition to reference counting) for memory
management and support for Unicode. However, the most important change was to the
development process itself, with a shift to a more transparent and community-backed process.
Python 3.0, a major, backwards-incompatible release, was released on December 3, 2008
after a long period of testing. Many of its major features have also been backported to the
backwardscompatible Python 2.6 and 2.7.

First publication

In February 1991, Van Rossum published the code (labeled version 0.9.0) to alt sources.
Already present at this stage in development were classes with inheritance exception

54
handling, functions, and the core datatypes of list, dict, str and so on. Also in this initial
release was a module system borrowed from Modula-3.Van Rossum describes the module as
"one of Python's major programming units". Python's exception model also resembles
Modula-3's, with the addition of an else clause.In 1994 comp .lang. python the primary
discussion forum for Python, was formed, marking a milestone in the growth of Python's
userbase.

Version release dates

Release dates for the major and minor versions:

• Python 1.0 - January 1994 o Python


1.5 - December 31, 1997 o Python
1.6 - September 5, 2000
• Python 2.0 - October 16, 2000 o
Python 2.1 - April 17, 2001 o
Python 2.2 - December 21, 2001
o Python 2.3 - July 29, 2003 o
Python 2.4 - November 30, 2004
o Python 2.5 - September 19,
2006 o Python 2.6 - October 1, 2008 o
Python 2.7 - July 3, 2010
• Python 3.0 - December 3, 2008 o
Python 3.1 - June 27, 2009 o
Python 3.2 - February 20, 2011
o Python 3.3 - September 29,
2012 o Python 3.4 - March 16, 2014 o
Python 3.5 - September 13,
2015 o Python 3.6 - December 23, 2016

Version 1.0 (1994)

Python reached version 1.0 in January 1994. The major new features included in this release
were the functional programming tools lambda, mapfilter and reduce. Van Rossum stated that
"Python acquired lambda, reduce(), filter() and map(), courtesy of a Lisp hacker who missed
them and submitted working patches"

The last version released while Van Rossum was at CWI was Python 1.2. In 1995, Van
Rossum continued his work on Python at the Corporation for National Research Initiatives
(CNRI) in Reston, Virginia whence he released several versions.

By version 1.4, Python had acquired several new features. Notable among these are the
Modula-3 inspired keyword arguments(which are also similar to Common Lisp's keyword
arguments) and built-in support for complex numbers. Also included is a basic form of data
hiding by name mangling, though this is easily bypassed.

Python served a central role in this: because of its focus on clean syntax, it was already
suitable, and CP4E's goals bore similarities to its predecessor, ABC. The project was funded

55
by DARPA. As of 2007, the CP4E project is inactive, and while Python attempts to be easily
learnable and not too arcane in its syntax and semantics, reaching out to non-programmers is
not an active concern.

GETTING STARTED

1.Running python as a calculator The easiest way to get started is to run python as an
interpreter, which behaves similar to the way one would use a calculator .In the interpreter
,you type a command, and python produces the answer .then u type another command ,which
again produces an answer ,and so on .In OS X or Linux, to start the python interpreter is as
simple as typing the command python on the command line in a terminal shell .In windows
,assuming that python has already been installed, you need to find python on the appropriate
menu. Windows users can choose to run python in a command shell where it will behave
very similarly to Linux or OS X.

For all three operating systems there is also an integrated development environment for
python named IDLE. If interested,you may download and install this on your computer .Once
python start running in interpreter mode ,using IDLE or a command shell ,it produces a
prompt ,which waits for ur input .for example ,this is what i get when I start python in my
command shell or my Linux box.
2.QUITTING THE INTERPRETER
In a terminal you can quit python session by CTRL-D. In IDLE you can also quit from the
menu.

If the interpreter gets struck in an infinite loop, you can quit the current execution by CTRL-
C.

3. Loading commands from the library:


Python has a very extensive library of commands, documented in the Python Library
Reference Manual. These commands are organised into modules.

4. Defining functions:
It is possible and very useful to define our own functions in python. Generally speaking, if
you need to do a calculation only once ,then use the interpreter. But when u or others have
need to perform certain type of calculation many times then define a function. For a simple
example, the compound command >>>def f(x):

... return x**x


...

defines the squaring function f(x)=x^2,a popular example used in elementary math courses In
the definition ,the first line is the function header where the name, of the function is specified.

56
subsequent lines give the body of the function, where the output value is calculated. Note that
final step is to return the answer; without it we would never see any results .continuing the
example ,we can use the function to calculate the square of any given input :

>>>f(2)

>>> f(2.5)

6.25

5. FILES:
Python allows us to store our code in files(also called modules).This is very useful for more
serious to change one mistake .In doing this ,we are essentially defining our own modules
,just like the modules defined already in the python library

PYTHON FEATURES

Python's features include:

• Easy-to-learn: Python has few keywords, simple structure, and a clearly defined
syntax. This allows the student to pick up the language quickly.
• Easy-to-read: Python code is more clearly defined and visible to the eyes.
• Easy-to-maintain: Python's source code is fairly easy-to-maintain.
• A broad standard library: Python's bulk of the library is very portable and
crossplatform compatible on UNIX, Windows, and Macintosh.
• Interactive Mode:Python has support for an interactive mode which allows
interactive testing and debugging of snippets of code.
• Portable: Python can run on a wide variety of hardware platforms and has the same
interface on all platforms.
• Extendable: You can add low-level modules to the Python interpreter. These
modules enable programmers to add to or customize their tools to be more efficient.
• Databases: Python provides interfaces to all major commercial databases.
• GUI Programming: Python supports GUI applications that can be created and ported
to many system calls, libraries and windows systems, such as Windows MFC,
Macintosh, and the X Window system of Unix.
• Scalable: Python provides a better structure and support for large programs than shell
scripting.
Apart from the above-mentioned features, Python has a big list of good features, few are
listed below:

• It supports functional and structured programming methods as well as OOP.


• It can be used as a scripting language or can be compiled to byte-code for building
large applications.
• It provides very high-level dynamic data types and supports dynamic type checking.
• IT supports automatic garbage collection.
• It can be easily integrated with C, C++, COM, ActiveX, CORBA, and Java.

57
STEPS FOR INSTALLATION OF
WINDOW 8
Select your language. Once the Windows 8 installation begins, you will be prompted to
select a language, time and currency format, and keyboard layout. Once you select these,
click Next.

58
STEP 2:
Click Install Now. This will begin the installation process. The other option is for repairing
an existing Windows installation.

59
STEP 3:

60
Enter your product key. This is the 25 character key that came with your purchased copy of
Windows 8. It may be located on a sticker on your computer or underneath your laptop.

• You do not need to enter the dashes between the groups of characters.

• This is not an optional step. Previous versions of Windows allowed you to register
your product up to 60 days after installing. You must now enter the key before
installation begins.

61
STEP 4:
Accept the license agreement. Once you have read the agreement, check the box signifying
that you accept the agreement and click next.

62
STEP 5:
Click Custom Install. You will have two options to install windows. Picking Custom will
allow you to do a complete installation of Windows 8. Selecting upgrade can cause
performance problems in the long run. It is highly recommended that you do a clean Custom
Install.

63
STEP 6:
Delete the partition. A window will open asking where you would like to install Windows 8.
In order to perform a clean install, you need to delete the old partition and start with a clean
slate. Click “Drive options (advanced).” This will give you the ability to delete and create
partitions.

• Select the partition of your existing operating system and click the Delete button.

64
• If you are installing an operating system for the first time on this hard drive, then
there will be no partitions to delete.

65
• If your hard drive has multiple partitions, be sure to delete the correct one. Any data
on a deleted partition is lost for good.
• Confirm the deletion process.

66
67
STEP 7:
Select the Unallocated Space and click Next. There is no need to create a partition before
you install Windows 8, this is done automatically.

68
STEP 8:
Wait while Windows installs files. The percentage next to Expanding Windows files will
steadily increase. This part of the process can take up to 30 minutes.

• Windows will automatically restart your computer when finished.

69
70
STEP 9:
Wait while Windows gathers information. After the computer reboots, you will see the
Windows 8 logo. Beneath it will be the text “Getting devices ready” followed by a percentage.
Windows is collecting information on the hardware installed in your computer.

• When this is done, the text will change to “Getting ready”.


• Your computer will restart one more time.

71
STEP 10:
Personalize your Windows 8.Once the computer finishes rebooting, you will be asked to pick
the color scheme for your installation of Windows 8.

• You can change the color at any time in the Windows 8 settings.

72
STEP 11:
Enter a computer name. This is the name that the computer displays on the network. Any
other device on the network will see your computer listed with this name.
STEP 12:
Choose your wireless network. If you have a wireless-enable computer or device, you will
see a menu asking you to choose a network. If you haven’t installed the driver for your
wireless card yet, this step will automatically be skipped.

73
Step 13
Choose your settings.The most common option is Express Settings, which will enable
automatic updates, Windows Defender, and error reporting to Microsoft, among other things.

• If you’d rather set these yourself, choose Customize instead of Express Settings.

74
75
STEP 14:
Create an account. To log in to Windows, you will need an account. Microsoft recommends
using a Microsoft account, so that you can make purchases in the Windows store. If you don’t
have a Microsoft account, entering a valid email address will create one for free.

• If you don’t have an email address, click the “Sign up for a new email address” link
to create one. This requires an internet connection.

76
• If you’d rather sign in the old way, without using a Microsoft account, click the
bottom link. This will create a login similar to previous versions of Windows.

77
78
Program:-1
Write A program to represent your bio data
a=input("enter your name")

b=int(input("enter your roll no"))

c=input("enter your stream")

d=input("enter your address")

print("name:", a)

print("roll no:", b)

print("stream:", c)

print("address:", d)

79
PROGRAM-2

Write A Program to print grades of the students

a=int(input("enter value of english"))

b=int(input("enter value of math"))

c=int(input("enter value of computer")) d=(a+b+c)/3

if(d>90):

print("enter grade a") elif(90>d>80):

print("enter grade b") else:

print("enter grade c")

PROGRAM-3

WRITE A PROGRAM TO CHECK WHETHER A NUMBER IS ODD OR


EVEN
a=int(input("enter your number")); if(a%2==0):

80
print("no is even") else:

print("no is odd")

PROGRAM 4

WRITE A PROGRAM TO CHECK WHETHER A NUMBER IS PRIME


OR NOT

81
a=int(input("enter a number"));

f=0; for i in range(2,a):

if(a%i==0):

f=1;

break;

if(f==1):

print ("Not Prime");

else: print("prime

number")

PROGRAM-5

WRITE A PROGRAM TO PRINT TABLE OF ANY NUMBER


n=30

for i in range(1,20):

print(n,"*",i,"=",(n*i))

82
Program 6

WRITE A PROGRAM TO CHECK A NO IS NEGATIVE, POSITIVE OR


ZERO
num=int(input("enter a number")); if(num>0):

print("number is positive"); elif(num<0):

print("number is negative"); else:

83
print("number is zero"); output:

Program 7

WRITE A PROGRAM TO FIND SQUARE ROOT OF A NUMBER


a=int(input("enter a number")); b=a**0.5;

print(b);

84
Program 8

WRITE A PROGRAM TO FIND AREA OF TRIANGLE


a=int(input("enter a number"));

b=int(input("enter a number"));

c=int(input("eneter a number"));

s=(a+b+c)/2; area=(s*(s-a)*(s-

b)*(s-c)); print(area) output:

85
Program 9

WRITE A PROGRAM TO FIND GREATER OF THREE NUMBERS


a=int(input("enter a number"));

b=int(input("enter a number"));

c=int(input("enter a number"));

if(a>b)and(a>c): print("a is

greater");

elif(b>a)and(b>c):

print("b is greater"); else:

print("c is greater");

86
output:

Program 10

WRITE A PROGRAM TO APPLY MEMBERSHIP OPERATOR IN AND


NOT IN
a=10; b=20;

list=[1,2,3,4,5];

if(a in list):

print("line-1-a is available in the given list"); else:

print("line1-a is not available in the list"); if(b

not in list):

print("line2- b is not available in the list"); else:

print("line2-b is available in the list");

87
Program 11

WRITE A PROGRAM TO APPLY IDENTITY OPERATOR IS AND IS


NOT
a=20; b=20;

if(a is b):

print("line1-a and b have same identity") else:

print("line1-a and b do not have same identity");

b=30;

if(a is b ):

print("line2-a and b have same identity") else:

print("line2-a and b do not have same identity"); output:

88
PROGRAM 12:

WRITE A PROGRAM TO PRINT PRIME NUMBERS BETWEEN 0 TO


100
for a in range(1,100+1):

b=0; for i in

range(1,a+1):

if(a%i==0):

b=b+1; if(b==2):

print(a) output:

89
PROGRAM 13:

WRITE A PROGRAM TO FIND SUM OF NATURAL NUMBERS USING


RECURSION
def recur_sum(n):

if (n<=1):

return n else:

return n+recur_sum(n-1)

num=int(input("enter a number")) if

(num<0):

print("enter a positive number") else:

print("The sum is ",recur_sum(num)) output:

90
PROGRAM 14:

WRITE A PROGRAM TO IMPLEMENT SUM OF NUMBERS UNTIL


ZERO
a=1;

sum=0

while(a!=0): a=int(input("enter

any number")) sum=sum+a

print('total sum is:',sum) output:

91
PROGRAM 15:

WRITE A PROGRAM TO DETERMINE SUM OF A NUMBER


def sum(arg1,arg2):

total=arg1+arg2;

print(total)

sum(10,20) output:

92
PROGRAM 16:

WRITE A PROGRAM TO DETERMINE REVERSE OF A NUMBER


a=1234; reverse=0;

while(a>0):

remainder=a%10;

reverse=(reverse*10)+remainder;

a=a//10; print("the reverse of number

is",reverse) output:

93
PROGRAM 17:

WRITE A PRROGRAM TO DETERMINE FACTORIAL OF A


NUMBER
num=int(input("enter a number"));

factorial=1;O if (num<0):

print("factorial does not exist");

elif(num==0):

print("factorial is 1");

else: for i in

range(1,num+1):

94
factorial=(factorial*i);

print(factorial) output:

PROGRAM 18:

WRITE A PROGRAM TO DETERMINE A NO IN DIFFERENT


LANGUAGES
dec=20

print(bin(dec))

print(hex(dec))

print(oct(dec)) output:

95
PROGRAM 19:

WRITE A PROGRAM TO PRINT FIBONACCI SERIES


num=int(input("enter a number"));

p=0; c=1;

print(p); print(c); for i

in range(1,num+1):

n=(p+c)

96
print(n)

p=c; c=n;

output:

PROGRAM 20:

WRITE A PROGRAM TO PRINT FIBONNICI SERIES USING


RECURSION
def recur_fibo(n):

if(n<=1):

return n else:

return(recur_fibo(n-1)+recur_fibo(n-2))

nterms=int(input("enter a number")) if

(nterms<=0):

print("please enter a positive integer") else:

97
print("fibonnici sequence:")

for i in range(nterms):

print(recur_fibo(i)) output:

PROGRAM 21:

WRITE A PROGRAM TO CHECK WHETHER NUMBERS IN THE


LIST IS DIVISIBLE BY TWO OR NOT USING FILTER

my_list=[12,65,54,39,102,339,221]

result=list(filter(lambda x%2==0),my_list))

print(“numbers divisible by 2 are “,result)

output:

98
PROGRAM 22:

WRITE A PROGRAM TO PRINT SQUARE OF NUMBERS USING


MAP_ANONYMOUS FUNCTION
square = lambda x: x ** 2

print(square(5)) output:

99
PROGRAM 23:

WRITE A PROGRAM TO MAKE A CALCULATOR BY CREATING


MODULES
def add(x, y):

"""This function adds two numbers"""

return x + y

100
def subtract(x, y):

"""This function subtracts two numbers"""

return x - y

def multiply(x, y):

"""This function multiplies two numbers"""

return x * y

def divide(x, y):

"""This function divides two numbers"""

return x / y

# take input from the user

print("Select operation.")

print("1.Add") print("2.Subtract")

print("3.Multiply")

print("4.Divide")

choice = input("Enter choice(1/2/3/4):")

num1 = int(input("Enter first number: ")) num2

= int(input("Enter second number: "))

if choice == '1':

print(num1,"+",num2,"=", add(num1,num2))

elif choice == '2':

101
print(num1,"-",num2,"=", subtract(num1,num2))

elif choice == '3':

print(num1,"*",num2,"=", multiply(num1,num2))

elif choice == '4':

print(num1,"/",num2,"=", divide(num1,num2))

else:

print("Invalid input") output:

PROGRAM 24:

WRITE A PROGRAM TO PRINT TABLE OF A NUMBER USING


RAISED POWER AS A VARIABLE
n=int(input("enter a number")) terms = 10 result

= list(map(lambda x: n ** x, range(terms)))

print("The total terms is:",terms) for i in

range(terms):

print("n raised to power",i,"is",result[i]) output:

102
PROGRAM 25:

WRITE A PROGRAM TO FIND REVERSE OF A NUMBER AND TO


CHECK WHETHER IT IS PRIME OR NOT
a=1234; reverse=0;

while(a>0):

remainder=a%10;

reverse=(reverse*10)+remainder;

a=a//10; print("the reverse of number

is",reverse) a=2; isPrime=True

while(reverse>a): if (reverse%a==0):

isPrime=False

break else:

103
a=a+1;

if(isPrime):

print(“number is prime”) else:

print(“not prime”)

104

You might also like