Python Programming Lab Manual
Python Programming Lab Manual
LABORATORY
MANUAL & RECORD
B.TECH II YEAR – 2 SEM
PROGRAM-1 Date:
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:
PROGRAM-2 Date:
In the program below, the three numbers are stored in num1, num2 and num3 respectively. We've used
the if...elif...else ladder to find the largest among the three and display it.
Aim:
# Python program to find the largest number among the three input numbers
Output:
PROGRAM-3 Date:
Aim:
Accepts users input and perform the operation accordingly. Use functions with arguments.
Program:
def add(a,b):
return a+b
def sub(c,d):
return c-d
def mul(e,f):
return e*f
def div(g,h):
return g/h
print("=================")
print("1. TO PERFORM ADDITION")
print("2. TO PERFORM SUBTRACTION")
print("3. TO PERFORM MULTIPLICATION")
print("4. TO PERFORM DIVISION")
print("=================")
if choice == 1:
a = int(input("Enter the 1st value: "))
b = int(input("Enter the 2nd value: "))
print("Result: ", add(a,b))
elif choice == 2:
c = int(input("Enter the 1st value: "))
d = int(input("Enter the 2nd value: "))
print("Result: ", sub(c,d))
elif choice == 3:
e = int(input("Enter the 1st value: "))
f = int(input("Enter the 2nd value: "))
print("Result: ", mul(e,f))
elif choice == 4:
g = int(input("Enter the 1st value: "))
h = int(input("Enter the 2nd value: "))
print("Result: ", div(g,h))
else:
print("Wrong choice")
Output:
PROGRAM-4 Date:
Aim:
A) Write a program to double a given number and add two numbers using lambda()?
Program:
print(double(5))
add = lambda x, y: x + y
print(add(5, 4))
Output:
PROGRAM-5 Date:
In Python, we can implement a matrix as a nested list (list inside a list). We can treat each element as a
row of the matrix.
For example X = [[1, 2], [4, 5], [3, 6]] would represent a 3x2 matrix. The first row can be selected
as X[0]. And, the element in the first-row first column can be selected as X[0][0].
Transpose of a matrix is the interchanging of rows and columns. It is denoted as X'. The element
at ith row and jth column in X will be placed at jth row and ith column in X'. So if X is a 3x2 matrix, X' will
be a 2x3 matrix.
Aim:
# Program to transpose a matrix using a nested loop
X = [[12, 7],
[4, 5],
[3, 8]]
Aim:
# Python3 program to calculate pow(x,n)
# Driver Code
x=2
y=3
print(power(x, y))
Output:
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:
PROGRAM-8 Date:
Aim:
Program:
def admin():
print("hi")
def cabin():
print("hello")
admin()
cabin()
Output:
PROGRAM-9 Date:
Aim:
A) Write a python Program to display welcome to WISTM T by using classes and objects.
Program:
class Display:
def displayMethod(self):
print("Welcome to WISTM")
# Object creation
obj = Display()
obj.displayMethod()
Output:
PROGRAM-10 Date:
Aim:
A) Using a numpy module create an array and check the following:
Program:
import numpy as np
Aim:
A) Write a python program to concatenate the dataframes with two different objects.
Program:
import pandas as pd
Aim:
Program:
f = open("basicpython.txt", "w")
f.write("Woops! I have deleted the content!")
f.close()
Output: