0% found this document useful (0 votes)
5 views

1649321220_PYTHON

Uploaded by

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

1649321220_PYTHON

Uploaded by

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

PYTHON PROGRAMMING LAB MANUAL

I YEAR II SEMESTER

2018 - 19

Prepared by:

Smt.CH.Suguna Latha
Assistant Professor

Sri. T.Balaji
Assistant Professor

GUDLAVALLERU ENGINEERING COLLEGE


(An Autonomous Institute with Permanent Affiliation to JNTUK, Kakinada)
Seshadrirao Knowledge Village, Gudlavalleru – 521356
GUDLAVALLERU ENGINEERING COLLEGE
(An Autonomous Institution with Permanent Affiliation to JNTUK, Kakinada)

Seshadri Rao Knowledge Village, Gudlavalleru – 521356

DEPARTMENT OF INFORMATION TECHNOLOGY

INSTITUTE VISION & MISSION

Institute Vision:

To be a leading institution of engineering education and research, preparing students for leadership in
their fields in a caring and challenging learning environment.

Institute Mission:

• To produce quality engineers by providing state-of-the-art engineering education.


• To attract and retain knowledgeable, creative, motivated and highly skilled individuals whose
leadership and contributions uphold the college tenets of education, creativity, research and
responsible public service.
• To develop faculty and resources to impart and disseminate knowledge and information to
students and also to society that will enhance educational level, which in turn, will contribute to
social and economic betterment of society.
• To provide an environment that values and encourages knowledge acquisition and academic
freedom, making this a preferred institution for knowledge seekers.
• To provide quality assurance.
• To partner and collaborate with industry, government, and R&D institutes to develop new
knowledge and sustainable technologies and serve as an engine for facilitating the nation’s
economic development.
• To impart personality development skills to students that will help them to succeed and lead.
• To instil in students the attitude, values and vision that will prepare them to lead lives of personal
integrity and civic responsibility.
• To promote a campus environment that welcomes and makes students of all races, cultures and
civilizations feel at home.
• Putting students face to face with industrial, governmental and societal challenges.
DEPARTMENT VISION & MISSION

VISION

To be a centre of innovation by adopting changes in Information Technology, imparting quality

education, research to produce visionary computer professionals and entrepreneurs.

MISSION

➢ To provide an academic environment in which students are given the essential resources for
solving real-world problems and work in multidisciplinary teams.

➢ To impart value based education and research among students, particularly belonging to rural
areas, for their sustained growth in technological aspects and leadership.

➢ To collaborate with the industry for making the students adoptable to evolving changes in
Information Technology and related areas.

PROGRAMME EDUCATIONAL OBJECTIVES(PEOs):-

PEO1:To exhibit analytical skills in modeling and solving computing problems by applying
mathematical, scientific and engineering knowledge and to pursue their higher studies.

PEO2: To communicate effectively with multi-disciplinary teams to develop quality software


systems with an orientation towards research and development for lifelong learning.

PEO3: To address industry and societal needs for the growth of global economy using emerging
technologies by following professional ethics.
.
PROGRAM OUTCOMES (POs)

Engineering students will be able to:

1. Engineering knowledge: Apply the knowledge of mathematics, science, engineering fundamentals, and
an engineering specialization to the solution of complex engineering problems.
2. Problem analysis: Identify, formulate, review research literature, and analyze complex engineering
problems reaching substantiated conclusions using first principles of mathematics, natural sciences,
and engineering sciences.
3. Design/development of solutions: Design solutions for complex engineering problems and design
system components or processes that meet the specified needs with appropriate consideration for the
public health and safety, and the cultural, societal, and environmental considerations.
4. Conduct investigations of complex problems: Use research-based knowledge and research methods
including design of experiments, analysis and interpretation of data, and synthesis of the information to
provide valid conclusions.
5. Modern tool usage: Create, select, and apply appropriate techniques, resources, and modern
engineering and IT tools including prediction and modeling to complex engineering activities with an
understanding of the limitations.
6. The engineer and society: Apply reasoning informed by the contextual knowledge to assess societal,
health, safety, legal and cultural issues and the consequent responsibilities relevant to the professional
engineering practice.
7. Environment and sustainability: Understand the impact of the professional engineering solutions in
societal and environmental contexts, and demonstrate the knowledge of, and need for sustainable
development.
8. Ethics: Apply ethical principles and commit to professional ethics and responsibilities and norms of the
engineering practice.
9. Individual and team work: Function effectively as an individual, and as a member or leader in diverse
teams, and in multidisciplinary settings.
10. Communication: Communicate effectively on complex engineering activities with the engineering
community and with society at large, such as, being able to comprehend and write effective reports
and design documentation, make effective presentations, and give and receive clear instructions.
11. Project management and finance: Demonstrate knowledge and understanding of the engineering and
management principles and apply these to one’s own work, as a member and leader in a team, to
manage projects and in multidisciplinary environments.
12. Life-long learning: Recognize the need for, and have the preparation and ability to engage in
independent and life-long learning in the broadest context of technological change.
PROGRAM SPECIFIC OUTCOMES

Students will be able to


13.

PSO1: Organize, maintain and protect IT Infrastructural resources.

PSO2: Design and Develop web, mobile, and smart apps based software solutions to the real
SNO NAME OF PROGRAMS Page
Nos.
1 Write a python program to print “Hello World!” on the screen.
2 Write a Python program to find sum of two numbers.
3 Write a Python program to compute distance between two points
taking input from the user. (use Pythagorean Theorem).
4 Write a python program to test whether a given number is even or odd.
5 Write a Python Program to print out the decimal equivalents of 1/2,
1/3, 1/4, . . . ,1/10, using a for loop.
6 Write a Python Program to print a countdown from the given number
to zero. Using a while loop.
7 Write a Python Program to find the sum of all the primes below
hundred.
8 Write a Python program to find the factorial of a given number
9 Write a function cumulative_product to compute cumulative product
of a list of numbers
10 Write function to compute gcd, lcm of two numbers. Each function
shouldn’t exceed one line.
11 Find the sum of the even-valued terms in the Fibonacci sequence
whose values do not exceed ten thousand.
12 Write a program that accepts a string from a user and re-displays the
same after removing vowels from it.
13 Write a program to calculate the length of a string.
14 Write a function to reverse a given string.
15 Creating Python Lists and deleting some elements, creating and
accessing Python tuple elements.
16 write a program to swap two values using Tuple assignments
17 Write a program to sort a Tuple of values
18 Write program that scans an email address and forms a tuple of user
name and domain name.
19 Write a program to print sum and average of the elements present in
the list.
20 Write a program that forms a list of first character of every word
present in another list.
21 Write a program to count the number of characters in the string and
store them in a dictionary.
22 Write a program to sort keys of a dictionary.
23 Write a program that prints maximum and minimum value in a
dictionary.
24 Write a program to print each line of a file in reverse order
25 Write a program to compute the number of characters, words and
lines in a file.
26 Write a program to copy contents of one file into another file.
1.Aim:- Write a Python program to print Hello-World

Program:-#To print Hello-world

>>>print(“Hello-World”)

Output :- Hello-World

(Or)

Program :- >>>a=”Hello”

>>>a+=”-World”

>>>print(a)

Output :-Hello-world
2. Aim :-Write a Python program to add two-numbers

Program:- >>>a=5

>>>b=10

>>>c=a+b

>>>print(c)

Output:- 15

(Or)

Program:- h=int(input(“Enter a:”))

s=int(input(“Enter b:”))

c=h+s

print(c)

Output:- Enter a:10


Enter b:15
25
3. Aim:-Write a python program to find distance between two points

Program:-x1=int(input("Enter x1:"))

x2=int(input("Enter x2:"))

y1=int(input("Enter y1:"))

y2=int(input("Enter y2:"))

distance=((x2-x1)**2+(y2-y1)**2)**0.5

print(“Distance between two points:”,+distance)

Output:-Enter x1:2

Enter x2:3

Enter y1:4

Enter y2:6

Distance between two points:3.6506

4. Aim: Write a python program to Test whether a given number is even or odd.
A) num = int(input("Enter a number: "))
if num % 2==0:
print("This is an even number.")
else:
print("This is an odd number.")
Output:
Enter a number: 5
This is an odd number.
5. Aim:. Write a python program to Print out the decimal equivalents of ½, 1/3
,1/4........1/10,using for a loop.
A) i=1
for i in range(1,11):
value=1.0/i
print"1/",i,"=",value
output:
1/ 1 = 1.0
1/ 2 = 0.5
1/ 3 = 0.333333333333
1/ 4 = 0.25
1/ 5 = 0.2
1/ 6 = 0.166666666667
1/ 7 = 0.142857142857
1/ 8 = 0.125
1/ 9 = 0.111111111111
1/ 10 = 0.1

6. Aim: Write a python program to Print a count down from the given number to zero using a
while loop.
A) num=int(input("enter a number"))
print "count down from ",num,"to 0:"
while (num>=0):
print num
num=num-1
output:
enter a number6
count down from 6 to 0:
6
5
4
3
2
1
0
7. Aim: Write a python program to Find the sum of all the primes below hundred.
A) sum=0
for j in range(1,100):
for i in range(2,j):
if (j% i) == 0:
break
else:
sum=sum+j #where j is a prime number
print "sum of prime numbers up to 100 is", sum
output:
sum of prime numbers up to 100 is 1061
8. Aim: Write a python program to find the factorial of a given number.
A) num=int(input("enter a number"))
fact=1
while (num>0):
fact=fact*num
num=num-1
print "factorial of a given number is",fact
output:
Enter a number 6
Factorial of a given number is 720

9. Aim: Write a function cumulative product to compute cumulative product of a list of numbers.
Program:
defcumulative_product():
list=[1,2,3,4]
prod=1
fori in list:
prod=prod*i
print(prod)
cumulative_product()
Output:
24
10. Aim: Write function to compute gcd, lcm of two numbers. Each function shouldn’t exceed one
line.
Program:
from fractions import gcd
print(gcd(5,25))
def lcm(a,b):
#a=60
#b=40
print((a * b) // gcd(a, b))
lcm(5,25)
output:
5
25

11. Aim:Find the sum of the even-valued terms in the Fibonacci sequence whose values do not
exceed ten thousand.
program:
i=0
j=1
sum=0
while(i<10000):
i=i+j
j=i-j
if(i%2==0):
sum+=i
print(sum)
output:
14328
12.Aim: Write a program that accepts a string from a user and re-displays the same after removing
vowels from it.
Program:
while True:
print('Enter x for exit.')
string = input('Enter any string: ')
if string == 'x':
break
else:
newstr = string
print("\n Removing vowels from the given string...")
vowels = ('a', 'e', 'i', 'o', 'u')
for x in string.lower():
if x in vowels:
newstr = newstr.replace(x,"")
print("New string after successfully removing all vowels!")
print(newstr,"\n")
output:
>>>
Enter x for exit.
Enter any string: programming

Removing vowels from the given string...


New string after successfully removing all vowels!
prgrmmng

Enter x for exit.


Enter any string: x
>>>
13.Aim:. Write a program to calculate the length of a string.
Program:
string=input("Enter string:")
count=0
fori in string:
count=count+1
print("Length of the string is:")
print(count)
output:
Enter string:i love india
Length of the string is:
12

14.Aim:Write a function to reverse a given string.

Program:
def reverse(text):
lst = []
count = 1
fori in range(0,len(text)):
lst.append(text[len(text)-count])
count += 1
lst = ''.join(lst)
returnlst
print reverse('Python Programming')

output:

gnimmargorPnohtyP
15. Aim: Creating Python Lists and deleting some elements, creating and
accessing Python tuple elements.
Creating tuple:
# Empty tuple

my_tuple = ()

print(my_tuple) # Output: ()

# Tuple having integers

my_tuple = (1, 2, 3)

print(my_tuple) # Output: (1, 2, 3)

# tuple with mixed datatypes

my_tuple = (1, "Hello", 3.4)

print(my_tuple) # Output: (1, "Hello", 3.4)

# nested tuple

my_tuple = ("mouse", [8, 4, 6], (1, 2, 3))

# Output: ("mouse", [8, 4, 6], (1, 2, 3))

print(my_tuple)

Deleting Tuple:

my_tuple = ('p','r','o','g','r','a','m','i','z')

# can't delete items

# TypeError: 'tuple' object doesn't support item deletion

# del my_tuple[3]

# Can delete an entire tuple

del my_tuple

# NameError: name 'my_tuple' is not defined

print(my_tuple)
16.Aim Write a program to swap two values using Tuple assignments.

Program: (val1,val2,val3)=(1,2,3)
(tup1,tup2,tup3)=(4,5,6)
(a,b,c)=(val1,val2,val3)
(val1,val2,val3)=(tup1,tup2,tup3)
(tup1,tup2,tup3)=(a,b,c)
print (val1,val2,val3)
print (tup1,tup2,tup3)
Output:

17.Aim: Write a program to sort a Tuple of values.


Program: tup=[5,1,40,8,6,2,1]
print(sorted(tup))
Output:
18.Aim: Write program that scans an email address and forms a tuple of user name and domain
name.

Program:
addr =input('Enter email address:')
(uname, domain) = addr.split('@')
print('Username:',uname)
print('domain name:',domain)

Output:

Enter email address:[email protected]


Username: gec
domain name: gmail.com

19.Aim: Write a program to print sum and average of the elements present in the list.

Program:
lst = [ ]
num = int(input('How many numbers: '))
for n in range(num):
numbers = int(input('Enter number '))
lst.append(numbers)
print("Sum of elements in given list is :", sum(lst))
avg=sum(lst)/num
print(avg)
Output:
20.Aim: Write a program that forms a list of first character of every word present in another list.
Program:
b= [ ]
l= ["gudlavalleru","engineering","college"]
for item in l:
b.append(item[0])
print(b)

Output: [‘g’,’e’,’c’]
21.Aim: Write a program to count the number of characters in the string and
store them in a dictionary.
n=int(input("enter number"))

dict={}

i=0

while(i<n):

str=input("enter string")

length=len(str)

dict[str]=length

i=i+1

print("dictionary is:",dict)

output:

enter number2

enter stringsuguna

enter stringraghu

dictionary is: {'suguna': 6, 'raghu': 5}


22. Aim: Write a program to sort keys of a dictionary.

dict={'name':'suguna','course':'M.Tech'}

for key in sorted(dict):

print("{%s:%s}"%(key, dict[key]))

output:

{course:M.Tech}

{name:suguna}

23. Aim: Write a program that prints maximum and minimum value in a
dictionary.

dict={'name':'suguna','course':'M.Tech'}

print("minimum value is",min(dict.values()))

print("Maximum value is:",max(dict.values()))

output:

minimum value is M.Tech

Maximum value is: suguna

24. Aim: Write a program to print each line of a file in reverse order

with open('input.txt','r')as fp:

for line in fp:

print(line[::-1])

output:

ih

olleh

u r woh
25. Aim: Write a program to compute the number of characters, words and
lines in a file.

num_line=0

num_words=0

num_char=0

with open('input.txt','r')as fp:

for line in fp:

words=line.split()

num_line+=1

num_words+=len(words)

num_char+=len(line)

print("no.of line=",num_line)

print("no.of characters:",num_char)

print("no.of words=",num_words)

output:

no.of line= 3

no.of characters: 17

no.of words= 5

26. Aim: Write a program to copy contents of one file into another file.

with open('input.txt')as fp:

with open('output.txt','w')as f1:

for line in fp:

f1.write(line)

output:

file content copied.

For all files programs the input file is

Input.txt

hi

hello

how r u

You might also like