Python Programming (R18A0588) : Laboratory Manual
Python Programming (R18A0588) : Laboratory Manual
Python Programming (R18A0588) : Laboratory Manual
[R18A0588]
LABORATORY MANUAL
B.TECH III YEAR – I SEM
[A.Y:2021-2022]
(Affiliated to JNTUH, Hyderabad, Approved by AICTE - Accredited by NBA & NAAC – ‘A’ Grade - ISO 9001:2015
Certified)Maisammaguda, Dhulapally (Post Via. Hakimpet), Secunderabad – 500100, Telangana State, India
Maisammaguda, Dhulapally (Post Via. Hakimpet), Secunderabad – 500100, Telangana State, India
VISION
➢ To achieve high quality in technical education that provides the skills and attitude to adapt to the
global needs of the Information Technology sector, through academic and research excellence..
MISSION
➢ To equip the students with the cognizance for problem solving and to improve the teaching
➢ To strengthen the knowledge base of the faculty and students with motivation towards possession of
➢ To promote the necessary moral and ethical values among the engineers, for the betterment of
the society.
PROGRAMME EDUCATIONAL OBJECTIVES (PEOs)
After the completion of the course, B. Tech Information Technology, the graduates will have the following
Program Specific Outcomes:
2. Lab Outcomes:
Upon completion of the course, students will be able to
About lab:
Python is a general purpose, high-level programming language; other high- level languages you might
have heard of C++, PHP, and Java. Virtually all modern programming languages make us ofan
Integrated Development Environment (IDE), which allows the creation, editing, testing, and saving of
programs and modules. In Python, the IDE is called IDLE (like many items in the language, this is a
reference to the British comedy group Monty Python, and in this case, one of its members, Eric Idle).
Many modern languages use both processes. They are first compiled into a lower level language, called
byte code, and then interpreted by a program called a virtual machine. Python uses both processes, but
because of the way programmers interact with it, it is usually considered an interpreted language.
Practical aspects are the key to understanding and conceptual visualization Of theoretical aspects
covered in the books. Also, this course is designed to review the concepts of Data Structure using C,
studied in previous semester and implement the various algorithms related to different data structures.
MALLA REDDY COLLEGE OF ENGINEERING & TECHNOLOGY
Maisammaguda, Dhulapally Post, Via Hakimpet, Secunderabad – 500100
Aim:
Program:
a=[1,3,5,6,7,[3,4,5],"hello"]
print(a)
a.insert(3,20)
print(a)
a.remove(7)
print(a)
a.append("hi")
print(a)
len(a)
print(a)
a.pop()
print(a)
a.pop(6)
print(a)
a.clear()
print(a)
Output:
Exercise Questions:
1) Print the dictionary items 2) access items 3) use get() 4)change values 5) use len()
Viva Questions:
1. Define list?
2. List out the methods of list?
3. What is list indexing and slicing with an example?
Record Notes
PROGRAM-2 Date:
A) Write a python program to add two numbers.
Program:
Output:
Exercise Questions:
D) Write a python Program to read a number and display corresponding day using if_elif_else?
Viva Questions:
1. What are called as flow control statements in python?
2. Define and list out python iteration statements with syntax?
3. What is a loop?
Record Notes
PROGRAM-3 Date:
Aim:
Accepts users input and perform the operation accordingly. Use functions with arguments.
Program:
def add(a,d):
return a+b
def sub(c,d):
return c-d
def mul(e,f):
return b*h
def div(g,h):
return s/s
print("=================")
print("=================")
if choice ==1:
a=int(input("Enter the 1st value"))
print(add(a,b))
print(sub(c,d))
print(mul(e,f))
print(areadOfSquare(s))
else:
print("wrong choice")
Output:
Exercise Questions:
B) Write a python program to check whether the given string is palindrome or not.
D) Write a Python function that takes two lists and returns True if they are equal otherwise false
Viva Questions:
1. Define function with syntax?
2. Differentiate between built – in and user-define functions?
3. Define and list out python function arguments?
Record Notes
PROGRAM-4 Date:
Aim:
A) Write a program to double a given number and add two numbers using lambda()?
Program:
print(double(5))
print(add(5,4))
Output:
Exercise Questions:
B) Write a program for filter() to filter only even numbers from a given list.
C) Write a program for map() function to double all the items in the list?
D) Write a program to find sum of the numbers for the elements of the list by using reduce()?
Viva Questions:
1. Define lambda function with syntax?
2. List out the built-in functions of anonymous functions?
3. Write the syntax for filter, map, reduce functions?
Record Notes
PROGRAM-5 Date:
Aim:
A) Demonstrate a python code to implement abnormal termination?
Program:
a=5
b=0
print(a/b)
print("bye")
Output:
Exercise Questions:
B) Demonstrate a python code to print try, except and finally block statements
C) Write a python program to open and write “hello world” into a file?
D) Write a python program to write the content “hi python programming” for the existing file.
Viva Questions:
1. Define exception?
2. List out different types of errors and exception?
3. Explain in brief how to handle exceptions?
4. Define file and what are the different modes of files?
Record Notes
PROGRAM-6 Date:
Aim:
A) Write a python program to get python version.
Program:
import sys
print("System version is:")
print(sys.version)
print("Version Information is:")
print(sys.version_info)
Output:
Exercise Questions:
B) Write a python program to open a file and check what are the access permissions acquired
bythat file using os module?
C) Write a python program to display a particular month of a year using calendar module.
Viva Questions:
1. Define module?
2. Explain how to reload a module?
3. Differentiate between built-in and user define modules?
Record Notes
PROGRAM-7 Date:
Aim:
A) Write a python program to print date, time for today and now.
Program:
import datetime
a=datetime.datetime.today()
b=datetime.datetime.now()
print(a)
print(b)
Output:
Exercise Questions:
B) Write a python program to add some days to your present date and print the date added.
C) Write a python program to print date, time using date and time functions
D) Write a python program which accepts the radius of a circle from user and computes the area
(use math module).
Viva Questions:
Aim:
Program:
def admin():
print("hi")
def cabin():
print("hello")
Output:
Exercise Questions:
B) Write a python program to create a package (Engg), sub-package( years),modules (sem) and
Viva Questions:
1. Define package?
2. What is structure of package show with an example?
3. Write the syntax for package with example?
Record Notes
PROGRAM-9 Date:
Aim:
A) Write a python Program to display welcome to MRCET by using classes and objects.
Program:
class display:
def displayMethod(self):
print("welcome to mrcet")
#object creation process
obj = display()
obj.displayMethod()
Output:
Exercise Questions:
B) Write a python Program to call data member and function using classes and objects.
C) Write a program to find sum of two numbers using class and methods
D) Write a program to read 3 subject marks and display pass or failed using class and object.
Viva Questions:
1. Define class and object creation with syntax?
2. What are the different types of constructors define them?
3. What is self-instance of a class?
Record Notes
PROGRAM-10 Date:
Aim:
A) Using a numpy module create an array and check the following:
Program:
import numpy as np
arr=np.array([[1,2,3],[4,2,5]])
print("Array is of type:",type(arr))
print("no.of dimensions:",arr.ndim)
print("Shape of array:",arr.shape)
print("Size of array:",arr.size)
Output:
Exercise Questions:
1. Reshape 3X4 array to 2X2X3 array 2. Sequence of integers from 0 to 30 with steps of 5
Aim:
A) Write a python program to concatenate the dataframes with two different objects.
Program:
import pandas as pd
one=pd.DataFrame({'Name':['teju','gouri'],
'age':[19,20]},
index=[1,2])
two=pd.DataFrame({'Name':['suma','nammu'],
'age':[20,21]},
index=[3,4])
print(pd.concat([one,two]))
Output:
Exercise Questions:
B) Write a python code to read a csv file using pandas module and print the first and last five
linesof a file.
Viva Questions:
1. Define pandas?
2. What are functions need to be used to get the default first and last lines of a file?
3. Define series,dataframes and panel?
Record Notes
PROGRAM-12 Date:
Aim:
A) Write a python code to set background color and pic and draw a circle using turtle module
Program:
import turtle
t=turtle.Turtle()
t.circle(50)
s=turtle.Screen()
s.bgcolor("pink")
s.bgpic("pic.gif")
Output:
Exercise Questions:
B) Write a python code to set background color and pic and draw a square and fill the color
using turtle module
C) Write a python code to perform addition using functions with pdb module.
Viva Questions: