data-structures-python-programming-lab-manual
data-structures-python-programming-lab-manual
Course ID : A43583
B.Tech-Semseter
(R20)
Program Outcomes-POs :
Program
Specific Statements
Outcomes
PSO1 Enhanced ability in applying mathematical abstraction and algorithmic design
along with programming tools to solve complexity involved in efficient
programming.
PSO2 Develop effective software skills and documentation ability for graduates to
become Employable/ Higher studies/Entrepreneur researcher.
Course Outcomes(COs):
CO-PO Mappings:
CO 1 3 3 3 3 3 2 2 2 1 3
CO 2 3 3 3 3 3 2 2 2 1 3
CO 3 3 3 3 3 3 2 2 2 1 3
CO 4 3 3 3 3 3 2 2 2 1 3
CO 5 3 3 3 3 3 2 2 2 1 3
Avg 3 3 3 3 3 2 2 2 1 3
CO-PSO Mappings:
Syllabus
Exercise 1
a) Installation and Environment setup of python.
b) Write a program to demonstrate the use of basic Data Types
c) Write a program to demonstrate the Operators and Expressions
d) Write a program to demonstrate the Functions and parameter passing Techniques.
Exercise 2
a) Write a Program to implement
i. Packages ii. Modules iii. Built-in Functions
b) Write a Program to implement
i. List ii. Tuple iii. Dictionaries
c) Programs on Stings, String Operations and Regular Expressions
Exercise 3
a) Write a Program to implement Class and Object
b) Write a Program to implement Static and Instance methods, Abstract Classes and
Interfaces.
Exercise 4
a) Write a program to compute distance between two points taking input from the user
(Pythagorean Theorem)
b) Write a program to convert a given decimal number to other base systems
Exercise 5
a) Write a program to implement Inheritance
b) Write a program to implement Polymorphism
Exercise 6
a) Write a program to implement Files
b) Write a program to Exception Handling.
Experiment - 1
Write a program to illustrate concepts of arrays, structures, unions and enumerated data
types.
Arrays:
#include <stdio.h>
int main() {
int values[5];
Structures:
struct Point
{
int x, y;
};
int main()
{
struct Point p1 = {0, 1};
return 0;
}
Output:
x = 20, y = 1
Unions:
#include <stdio.h>
#include <string.h>
union Data {
int i;
float f;
char str[20];
};
int main( ) {
return 0;
}
Output:
Memory size occupied by data : 20
Enum:
#include<stdio.h>
enum week{Mon=10, Tue, Wed, Thur, Fri=10, Sat=16, Sun};
enum day{Mond, Tues, Wedn, Thurs, Frid=18, Satu=11, Sund};
int main() {
printf("The value of enum week: %d\t%d\t%d\t%d\t%d\t%d\t%d\n\n",Mon , Tue, Wed, Thur,
Fri, Sat, Sun);
printf("The default value of enum day: %d\t%d\t%d\t%d\t%d\t%d\t%d",Mond , Tues, Wedn,
Thurs, Frid, Satu, Sund);
return 0;
}
Output
The value of enum week: 1011 12 13 10 16 17
The default value of enum day: 0 1 2 3 18 11 12
Experiment 2
Aim: Write a C program that uses stack operations to convert a given infix expression into its
postfix Equivalent, Implement the stack using an array.
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<conio.h>
char stack[20];
int top=-1;
char pop(); /*declaration of pop function*/
void push(char item); /*declaration of push function*/
intprcd(char symbol) /*checking the precedence*/
{
switch(symbol) /*assigning values for symbols*/
{
case '+':
case '-': return 2;
break;
case '*':
case '/':
case '%': return 4;
break;
case '(':
case ')':
case '#': return 1;
break;
}
intisoperator(char symbol) /*assigning operators*/
{
switch(symbol)
{
case '+':
case '*':
case '-':
case '/':
case '%':
case '(':
case ')':return 1;
break;
default: return 0;
}
}
}
pop(); /*function call for popping elements into the stack*/
}
else
{
if(prcd(symbol)>prcd(stack[top]))
push(symbol);
else
{
while(prcd(symbol)<=prcd(stack[top]))
{
postfix[j]=pop();
j++;
}
push(symbol);
}/*end of else */
}/*end of else */
} /*end of else */
}/*end of for loop*/
while(stack[top]!='#')
{
postfix[j]=pop();
j++;
}
postfix[j]='\0'; /*null terminate string*/
}
/*main program*/
void main()
{
char infix[20],postfix[20];
//clrscr();
printf("enter the valid infix string \n");
gets(infix);
convertip(infix,postfix); /*function call for converting infix to postfix */
/*push operation*/
void push(char item)
{
top++;
stack[top]=item;
}
/*pop operation*/
char pop()
{
char a;
a=stack[top];
top--;
return a;
}
Output:
Experiment 3
#include<stdio.h>
#include<conio.h>
#include<string.h>
#define MAX 50
int stack[MAX];
char postfix[20];
int top=-1;
void push(int item);
char pop();
void evaluate(char s);
void main()
{
inti,n,x;
char symbol;
// clrscr();
printf("Insert a postfix notation :: \n");
gets(postfix);
n=strlen(postfix);
for(i=0;i<n;i++)
{
symbol=postfix[i];
if(symbol>='0' && symbol<='9')
{
x=(int)(symbol-48);
push(x);
}
else
{
evaluate(postfix[i]);
}
}
printf("\n\nResult is :: %d",stack[top]);
getch();
}
void push(int x)
{
top++;
stack[top]=x;
}
char pop()
{
char x;
x=stack[top];
top--;
return x;
}
void evaluate(char d)
{
inta,b,c;
a=pop();
b=pop();
switch(d)
{
case '+':
c=a+b;
top++;
stack[top]=c;
break;
case '-':
c=a-b;
top++;
stack[top]=c;
break;
case '*':
c=a*b;
top++;
stack[top]=c;
break;
case '/':
c=a/b;
top++;
stack[top]=c;
break;
case '%':
c=a%b;
break;
top++;
stack[top]=c;
default:
c=0;
}
OUTPUT:
Insert a postfix notation: 432+*
Result is: 20
Experiment 4
#include<stdio.h>
#include<stdlib.h>
struct node
{
int value;
node* left;
node* right;
};
int main()
{
root= NULL;
int n, v;
return0;
}
if(r!=NULL){
inOrder(r->left);
printf("%d ", r->value);
inOrder(r->right);
}
}
}
}
OUTPUT:
How many data's do you want to insert? 7
20 15 25 16 24 12 30
Inorder Traversal: 12 15 16 20 24 25 30
Preorder Traversal: 20 15 12 16 25 24 30
Postorder Traversal: 12 16 15 24 30 25 20
Experiment 5
Aim: C program to illustrate insert, delete and searching operation in binary search tree
#include<stdio.h>
#include<stdlib.h>
struct node
{
int key;
struct node *left, *right;
};
returnnewNode(key);
else
{
// node with only one child or no child
if (root->left == NULL)
{
struct node *temp = root->right;
free(root);
return temp;
}
else if (root->right == NULL)
{
struct node *temp = root->left;
free(root);
return temp;
}
}
}
OUTPUT:
15
enetr 1.insertion 2.display 3.deletion. 4 exit
enter your choice
2
Inorder traversal of the given tree is: 12 16 20 24 25 30
Experiment 6
#include<stdio.h>
#include<stdlib.h>
/* Helper function that allocates a new node with the given key and
NULL left and right pointers. */
struct node* newNode(int key)
{
struct node* node = (struct node*)
malloc(sizeof(struct node));
node->key = key;
node->left = NULL;
node->right = NULL;
node->height = 1; // new node is initially added at leaf
return(node);
}
// Perform rotation
x->right = y;
y->left = T2;
// Update heights
y->height = max(height(y->left), height(y->right))+1;
x->height = max(height(x->left), height(x->right))+1;
// Perform rotation
y->left = x;
x->right = T2;
// Update heights
}
}
}
OUTPUT:
15
15 12 20
Experiment 7
#include <stdio.h>
#include<conio.h>
voidcreategraph();
voidbfs(); void display();
int g[10][10],n;
void main()
{
int v;
clrscr();
creategraph();
printf(“starting vertex is”);
scanf(“%d”,&v);
bfs(v);
getch();
}
voidcreategraph()
{
inti,j;
printf(“enter the number of nodes”);
scanf(“%d”,&n);
for(i=0;i”,v);
while(f<=r)
{
v=q[f];
f++;
for(i=0;i”,i);
visited[i]=1;
q[++r]=i;
}
}
Output:
Enter no of nodes 3
Edge present between A&A 0
Edge present between A&B 1
Edge present between A&C 1
Edge present between B&A 1
Edge present between B&B 0
A B C
A 0 1 1
B 1 0 1
C 1 1 0
#include<stdio.h>
#include <conio.h>
voidcreategraph();
voiddfs();
void display();
int g[10][10],n;
void main()
{
int v;
clrscr();
creategraph();
printf(“starting vertex is”);
scanf(“%d”,&v);
dfs(v);
getch();
}
voidcreategraph()
{
inti,j;
printf(“enter the number of nodes”);
scanf(“%d”,&n);
for(i=0;i=0)
{
v=st[top];
top--;
if(visited [v]==0)
{
printf(“%d->”,v);
visited [v]=1;
}
for(i=n-1;i>=0;i--)
{
if(g[v][i]!=0 && visited[i]==0)
{
st[++top]=i;
}
}}}
Output:
A B C D
A 0 1 1 0
B 1 0 0 1
C 1 0 0 0
D 0 1 0 0
Experiment -8:
Write a program to implement hash table using linear and quadratic probing
#include <stdio.h>
#include<stdlib.h>
#define TABLE_SIZE 10
int h[TABLE_SIZE]={NULL};
void insert()
{
int key,index,i,flag=0,hkey;
printf("\nenter a value to insert into hash table\n");
scanf("%d",&key);
hkey=key%TABLE_SIZE;
for(i=0;i<TABLE_SIZE;i++)
{
index=(hkey+i)%TABLE_SIZE;
if(h[index] == NULL)
{
h[index]=key;
break;
}
if(i == TABLE_SIZE)
int key,index,i,flag=0,hkey;
printf("\nenter search element\n");
scanf("%d",&key);
hkey=key%TABLE_SIZE;
for(i=0;i<TABLE_SIZE; i++)
{
index=(hkey+i)%TABLE_SIZE;
if(h[index]==key)
{
printf("value is found at index %d",index);
break;
}
}
if(i == TABLE_SIZE)
printf("\n value is not found\n");
}
void display()
{
int i;
}
main()
{
int opt,i;
while(1)
{
printf("\nPress 1. Insert\t 2. Display \t3. Search \t4.Exit \n");
scanf("%d",&opt);
switch(opt)
{
case 1:
insert();
break;
case 2:
display();
break;
case 3:
search();
break;
case 4:exit(0);
}
}
}
Output
at index 0 value = 0
at index 1 value = 0
at index 2 value = 12
at index 3 value = 13
at index 4 value = 22
at index 5 value = 0
at index 6 value = 0
at index 7 value = 0
at index 8 value = 0
at index 9 value = 0
Press 1. Insert 2. Display 3. Search 4.Exit
3
#include<stdio.h>
#include<stdlib.h>
/* each hash table item has a flag (status) and data (consisting of key and value) */
struct hashtable_item
{
int flag;
/*
* flag = 0 : data does not exist
* flag = 1 : data exists at given array location
* flag = 2 : data was present at least once
*/
struct item *data;
};
array[i].data = NULL;
}
}
}
i = (i + (h * h)) % max;
h++;
if (i == index)
{
printf("\n Hash table is full, cannot add more elements \n");
return;
}
}
array[i].flag = 1;
array[i].data = new_item;
printf("\n Key (%d) has been inserted\n", key);
size++;
}
/* to remove an element form the hash table array */
void remove_element(int key)
{
it index = hashcode(key);
int i = index;
int h = 1;
/* probing through the hash table until we reach at location where there had not been
an element even once */
while (array[i].flag != 0)
{
if (array[i].flag == 1 && array[i].data->key == key)
{
/* case where data exists at the location and its key matches to the
given key */
array[i].flag = 2;
array[i].data = NULL;
size--;
printf("\n Key (%d) has been removed \n", key);
return;
}
i = (i + (h * h)) % max;
h++;
if (i == index)
{
break;
}
}
printf("\n Key does not exist \n");
}
/* to display the contents of hash table */
void display()
{
int i;
for(i = 0; i < max; i++)
{
if (array[i].flag != 1)
{
printf("\n Array[%d] has no elements \n", i);
}
else
{
printf("\n Array[%d] has elements \n %d (key) and %d (value) \n", i
, array[i].data->key, array[i].data->value);
}
}}
int size_of_hashtable()
{
return size;
}
void main()
{
int choice, key, value, n, c;
clrscr();
array = (struct hashtable_item*) malloc(max * sizeof(struct hashtable_item*));
init_array();
do {
printf("Implementation of Hash Table in C with Quadratic Probing.\n\n");
printf("MENU-: \n1.Inserting item in the Hash table"
"\n2.Removing item from the Hash table"
"\n3.Check the size of Hash table"
"\n4.Display Hash table"
"\n\n Please enter your choice-:");
scanf("%d", &choice);
switch(choice)
{
case 1:
printf("Inserting element in Hash table \n");
printf("Enter key and value-:\t");
scanf("%d %d", &key, &value);
insert(key, value);
break;
case 2:
printf("Deleting in Hash table \n Enter the key to delete-:");
scanf("%d", &key);
remove_element(key);
break;
case 3:
n = size_of_hashtable();
printf("Size of Hash table is-:%d\n", n);
break;
case 4:
display();
break;
default:
printf("Wrong Input\n");
}printf("\n Do you want to continue-:(press 1 for yes)\t");
scanf("%d", &c);
}while(c == 1);
getch();
}
Output:
a= 5
print(a, "is of type", type(a))
a = 2.0
print(a, "is of type", type(a))
a = 1+2j
print(a, "is complex number?", isinstance(1+2j,complex))
Output:
5 is of type <class 'int'>
2.0 is of type <class 'float'>
(1+2j) is complex number? True
Output:
x + y = 19
x - y = 11
x * y = 60
x / y = 3.75
x // y = 3
x ** y = 50625
x = 10
y = 12
print('x > y is',x>y)
print('x < y is',x<y)
print('x == y is',x==y)
print('x != y is',x!=y)
Output:
x > y is False
x < y is True
x == y is False
x != y is True
x = True
y = False
print('x and y is',x and y)
print('x or y is',x or y)
print('not x is',not x)
Output:
x and y is False
x or y is True
not x is False
x1 = 5
y1 = 5
x2 = 'Hello'
y2 = 'Hello'
x3 = [1,2,3]
y3 = [1,2,3]
print(x1 is not y1)
print(x2 is y2)
print(x3 is y3)
Output:
False
True
False
x = 'Hello world'
y = {1:'a',2:'b'}
print('H' in x)
print('hello' not in x)
print(1 in y)
print('a' in y)
Output:
True
True
True
False
Output:
name =
Eeswar age =
20
Output:
name = Eeswar
sub = ('Python',)
name = Banala
sub = ('Python', 'Data Structures', 'Mathematics')
Exercise 2
a) Write a Program to implement
i. Packages ii. Modules iii. Built-in Functions
Output:
iam in IT module
iam in CSE module
FunParam.py
def add(a,b):
return (a+b)
def sub(a,b):
return b-a
def mul(a,b):
return a*b
def div(a,b):
return a/b
ModuleFrom.py
from FunParam import add,sub
sum=add(10,20)
print("Sum = ",sum)
diff=sub(10,20)
print("difference = ",diff)
Output:
Sum = 30
difference = 10
Output:
Absolute of -10.589 = 10.589
Binary Equalent of 16 0b10000
Quotient and remainder of 10/5 = (2, 0)
float value of 10 = 10.0
int value of 10.2 = 10
Maximum of 10,20,30 = 30
Minimum of 10,20,30 = 10
2 power 4 = 16
Square root of 25 = 5.0
stack=[]
print("Stack Implementation")
while(1):
op=int(input("1.Push 2.Pop 3.Display 4.Exit \nEnter your choice: "))
if(op==1):
n=input("enter a value:")
stack.append(n)
elif(op==2):
print("\npoped element is ",stack[-1])
stack.pop()
elif(op==3):
for index,i in enumerate(stack):
print(i,"is at index of ",index )
elif(op==4):
break
else:
print("Wrong Option")
Output:
Stack Implementation
1.Push 2.Pop 3.Display 4.Exit
Enter your choice: 1
enter a value:10
1.Push 2.Pop 3.Display 4.Exit
Enter your choice: 1
enter a value:20
1.Push 2.Pop 3.Display 4.Exit
Enter your choice: 1
enter a value:30
1.Push 2.Pop 3.Display 4.Exit
Enter your choice: 3
10 is at index of 0
20 is at index of 1
30 is at index of 2
1.Push 2.Pop 3.Display 4.Exit
Enter your choice: 2
poped element is 30
1.Push 2.Pop 3.Display 4.Exit
Enter your choice: 3
10 is at index of 0
20 is at index of 1
1.Push 2.Pop 3.Display 4.Exit
Enter your choice: 4
# vowels tuple
vowels = ('a', 'e', 'i', 'o', 'i', 'o', 'e', 'i', 'u')
# print count
print('The count of i is:', count)
# print count
print('The count of p is:', count)
Output:
The count of i is: 3
The count of p is: 0
Index of element a in tuple is: 0
# update value
my_dict['age'] = 18
print('Dictionary after upadte is : ', my_dict)
# add item
my_dict['address'] = 'Hyderabad'
print('Dictionary after adding addres is : ',my_dict)
Output:
Dictionary = {'name': 'Eeswar', 'age': 16}
Name = Eeswar
Age = 16
Dictionary after upadte is : {'name': 'Eeswar', 'age': 18}
Dictionary after adding addres is : {'name': 'Eeswar', 'age': 18,
'address': 'Hyderabad'}
Dictionary after removing age is : {'name': 'Eeswar', 'address':
'Hyderabad'}
Dictionary after removing all items : {}
s1="EswarBanala"
print(s1) #EswarBanala
print("s1[0:5]=", s1[0:5]) #Eswar
print("s1[5:]=", s1[5:]) #Banala
print("s1[:5]=",s1[:5]) #Eswar
print("s1[:]=",s1[:]) #EswarBanala
s1="EswarBanala"
print(s1) #EswarBanala
print("s1[0:5] = ",s1[0:5]) #Eswar
print("s1[0:5:1] = ",s1[0:5:1]) #Eswar
print("s1[0:5:2] = ",s1[0:5:2]) #Ewr
print("s1[0:20:3] = ",s1[0:20:3]) #Eaal
Output:
Concatenated String is : EeswarBanala
Output:
Eeswar Eeswar Eeswar Eeswar
Output:
enter your name:Eeswar
Hello Eeswar.. Welcome
Examples
matchObj=re.match('[E|e][a-z]+',line) #string starts with E or e
matchObj=re.match('^(E|e)[a-zA-Z]*',line)
matchObj=re.match('[R|S][a-z]+a$',line) #Namse starts with R or S and ends with a
matchObj=re.match('\d',line) #any single digit matchOb
j=re.match('\D',line) # Except digits matchObj=
re.match('\d+',line) # Minimum 1 digit matchOb
j=re.match('\d*',line) # Zero or n no. of digits
Output:
enter string:9885986909
9885986909
Matched!!
Output:
Enter a Mobile number:986879
Not matched!!
The syntax is similar to the match() function. The function searches for first occurrence of
pattern within a string with optional flags. If the search is successful, a match object is
returned and None otherwise.
Program
import re
str = "VJIT Hyderabad"
x = re.search("Hyderabad", str)
print(x)
Output:
<re.Match object; span=(5, 14), match='Hyderabad'>
The split() function returns a list without all the matched patterns of the string .
Syntax:
re.findall(Pattern, str)
Program
import re
str = "IT Dept VJIT"
x = re.findall("IT", str)
print(x)
x=re.split("IT",str)
print(x)
Output:
['IT', 'IT']
['', ' Dept VJ', '']
According to the syntax, the sub() function replaces all occurrences of the pattern in string
with repl, substituting all occurrences unless any max value is provided. This method returns
modified string.
Program
import re
s1="Delhi is the Best city in India."
s2=re.sub("Delhi","Hyderabad",s1)
print(s2)
s1="Delhi is the Best city in India. Delhi Delhi"
s2=re.sub("Delhi","Hyderabad",s1,2)
print(s2)
Output:
Hyderabad is the Best city in India.
Hyderabad is the Best city in India. Hyderabad Delhi
Exercise 3
a) Write Programs to implement Classes and Objects
# class methods
def disp(self):
print("inside the class method..")
def status(self,source,destination):
print("Train starts from ",source," and ends at ",destination)
# Accessing variables
print("T1 Name: ",T1.name)
print("T1 no: ",T1.no)
print("price: ",T1.price)
Output:
Enter Train Name: Venkatadri Express
Enter Train Number: 12345
Enter Price: 1500
T1 Name:Venkatadri Express
T1 no: 12345
price: 1500
inside the class method..
Train starts from Hyderabad and ends at Tirupati
class Student:
def init (self,r,n,m):
print("roll no = ", r)
print("name = " ,n)
tot=0
for i in range(len(m)):
print(m[i])
tot=tot+m[i]
print("total= ", tot)
avg=tot/6
print("average= ",avg)
s1=Student(roll,name,marks)
Output:
enter roll : 1208
enter name : Eeswar
enter marks :
49
39
40
60
90
57
roll no = 1208
name = Eeswar
49
39
40
60
90
57
total= 335
average= 55.833333333333336
Output:
Area of Rectangle = 8
Area of Square = 9
Area of Circle = 12.56
class Circle(Shape):
def init (self,r):
self.radius=r
def calculateArea(self):
area = math.pi * math.pow(self.radius,2)
print("Area of circle = ",area)
class Traingle(Shape):
def init (self,h,b):
self.height=h
self.base=b
def calculateArea(self):
area = (self.height * self.base)/2
print("Area of Traingle = ",area)
class Rectangle(Shape):
def init (self,l,w):
self.lenghth=l
self.width=w
def calculateArea(self):
area = self.lenghth * self.width
print("Area of Rectangle = ",area)
c1=Circle(2)
t1=Traingle(5,3)
r1=Rectangle(2,4)
c1.calculateArea()
t1.calculateArea()
r1.calculateArea()
Output:
Area of circle = 12.566370614359172
Area of Traingle =7.5
Area of Rectangle = 8
Exercise 4
a) Write a program to compute distance between two points taking input from the
user (Pythagorean Theorem)
import math
#Code
x1=int(input("enter x1: "))
y1=int(input("enter y1: "))
x2=int(input("enter x2: "))
y2=int(input("enter y2: "))
dis=distance(x1,y1,x2,y2)
print("distance=",dis)
Output:
enter x1: 5
enter y1: 4
enter x2: 7
enter y2: 8
distance= 4.47213595499958
def binarynum(num):
binnum=bin(num)
print(num," in binary is ",binnum)
def octnum(num):
octnum=oct(num)
print(num," in octal is ",octnum)
def hexnum(num):
hexnum=hex(num)
print(num," in Hexal decimal is ",hexnum)
Output:
enter a decimal number : 15
15 in binary is 0b1111
15 in octal is 0o17
15 in Hexal decimal is 0xf
Exercise 5
a) Write a program to implement Inheritance
class ICICI(Bank):
def getroi(self):
return 8;
b1 = Bank()
b2 = SBI()
b3 = ICICI()
print("Bank Rate of interest:",b1.getroi())
print("SBI Rate of interest:",b2.getroi())
print("ICICI Rate of interest:",b3.getroi())
Output:
Bank Rate of interest: 10
SBI Rate of interest: 7
ICICI Rate of interest: 8
r1=Rectangle(7,4)
r1.area()
r1.perimeter()
Output:
Area of Rectangle= 28
Perimeter of Rectangle= 22
obj1=SwiftDezire()
obj1.vehicleType()
obj1.brand()
obj1.speed()
obj2=Suziki()
obj2.vehicleType()
obj2.brand()
obj2.speed()
Output:
VehicleType : car
Brand : Suziki
Max Speed : 200 KMPH
VehicleType : car
Brand : Suziki
Max Speed : 120 KMPH
class Student:
def init (self,n):
self.name=n
def getName(self):
print("Name : ",self.name)
class Branch(Student):
def getBranch(self, dept):
print("Branch : ", dept)
class Score(Student):
def getScore(self,avg):
print("Academic Score : ", avg)
class Result(Branch,Score):
def getResult(self):
print('Result'.center(20,'*'))
self.getName()
self.getBranch('IT')
self.getScore(65)
r=Result("Eeswar")
r.getResult()
Output:
*******Result*******
Name : Eeswar
Branch :IT
Academic Score : 65
class Child(Parent):
def myMethod(self):
print('Calling child method')
Output:
Calling child method
Exercise 6
a) Write a program to implement Files
1) Program to implement file attributes
file=open("Sample1.txt","r")
print("Name of the file:",file.name)
print("File open status:",file.closed)
print("File opened mode:",file.mode)
print("Content in the file:")
print(file.read())
file.close()
print("File open status:",file.closed)
Output:
Name of the file: Sample1.txt
File open startus: False
File opened mode: r
Content in the file:
"FILES" DEMONSTRATION IN PYTHON...
File open status: True
Output:
New file "text2.txt"is created in the path.
Filepointer position when it was opened: 0
Filepointer position after seek(): 3
Contents in file: come to python class Happy Learning
Filepointer position after read(): 38
Output:
Enter numerator: 20
enter denominator: 0
Denominator is zero
this is finally block. this will be executed all the time..
Output:
Enter numerator: 10
enter denominator: 5
Qutioent= 2.0
this is finally block. this will be executed all the time..
Course:
DalashuchaR Pthonoqpcnul Evaluator: G incli1a
Date: Overall Score: 15M
5 4 3 2 1
Not
Moderate Normal Satisfied
Objects Out Standing Good Satisfied
Observation-5M
Record-5M
Execution -5M
HOD-T
tz2 ent
Lab Assessment:
Total 25M
HODIT
Heed of the Department
Dept. on nton ionoiogY
Vidya FE acio.ogy
:
0o u w
FMEEE:E
Downloaded by Anamta Abbas (anamtaabbas2@gmail.com)
VIDYA JYOTHI INSTITUTE OF
Aziz TECHNO
Nagar Gate, C.B Post,
Hyderabad 500075
NGY
DEPARTMENTOF INFORMATION
-
TECHNOLOGY
ContinuousLab AssessmentSheet
Date:O
Date:
Date:12110 Date: 26/jo Date:21
S.No.RollNo. o
26 20911A12E65 RE T 0 RO RE T E TOR E T Date:1/
Date: 1/ Date:
Date: [C Date 3o
30/11
o Date: / Date:7/1
| 2 RE T0 RE
T
27
28
20911A12E7
312 AS 54 31255515|5A 0
RE To R ET
29
20911A12E8
20911A12E9
23
31s 3122 3s
1o 3 S
4125|45
s32
30 20911A12F0 A SL 2 3o 5312 s 3
31 20911A12F1 2 2 o A 21 2 S2 33
A 2 A
38 20911A12F8 3sibs 32
39
20911A12F9 u5125a 3 to|4 A s3 2 2 2 S ID
40
312 A 2 3 se S2 S2-
20911A12G0
A S32 s 21S 231
5|32|1o2 o hS3|12 2 s |3 2 123 So
41
20911A12G15321os 3 5
A s23 114A
42 20911A12G2
4 2us12 2 23D2
43
20911A12G3 sM12 2
20911A12G4
44
s12E| 12 3s1us2 230 3 S2
45 20911A1265 253110
S126|
S|3122 So 5 3/253 SA3uSl2 1
D S 34512
12 2 |12
46
20911A12G6 A 3|S|23s4 S2
47
20911A12G7 L YAC 3 12 3l12 S o4S 2
48
20911A1268 12S2 3LSu312 2
49
20911A12G9S23 to 10 s 25443a |3 C 2 s 3|o 2 3 os2 3 Id
50
20911A12H0 S32 Su 3 S |1o S 323uS
51
20911A12H1 |12s2 12 S |4 5 12 5 Ss0su32
S2H|S AL Mu Is uS 23 1 4S
0-Obsenvation(5M),R - Record(5M), E Execution(SM), 31Marks2 3
-
T -Total (15M)
20911A12H2
s312S s
VIDYJYOTHIINSTITUTEOF TECHNOLUGY
Aziz Nagar Gate, C.B Post,
Hyderabad-500075
DEPARTMENTOF INFORMATION TECHNOLOGY
Continuous Lab AssessmentSheet
Date
SJODate: 2| Date: 26/1o | Date:21Date:1/1 Date: Ic Date:
30 u Date:9
S.No Roll No.
o R ETO RETo RET|o R E T|0 R E
T O R E T|oR E TO R E T
52 20911A12H2|5 35 5|/2
53 20911A12H3
55 4 3 2 7 5y 53 20515
A 2 Ab é 54 |3 n5|3 2 5
r
|5M53
54 20911A12H4 5|14
3122 4S B 25|105 2 15 4S/4245
60
20911A1210 3 2 5 |10 Ae 5 5 3 T5 2.5 S5 555 55
6121915A1210 3 5|72 5|4 2 y 31/|23 1S23 1oSS 453
6221915A1211 3 A 2 1041 235 l1oS 3 t2S3)
63
21915A1212susL 4E 2 s3|5 45 2 s 3 2S 3
64
21915A12135 21o2S 1S3|2 l2uS 3s 21D2 35/s3 1 15 23 ho
65
121423 SDh A 31S1 S|yu5 32 3s o 4 13
21915A1215
66
s n s23 zs2 1 37
67 21915A1216 Al r 532 O 3 2 3 S3 S124s3124S 3 7
6821915A1217 T Kfr a u s 23 S u 43 123 s|1s3 5/3
O-Observation (5M), R Record(5M),E
- -
Execution(5M),T -
Total Marks (15M)
(Course Instructor)