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

Practicals Word File

Uploaded by

Nishant
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
1 views

Practicals Word File

Uploaded by

Nishant
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 84

Program – 1

Objective- To understand the concept of if-elif-else statement.

Task- Write a Python script to enter the marks of five subjects


and calculate percentage with grade. Grade conditions are
Percentage Grade 91 to 100 - A, 81 to 90 – B, 71 to 80 – C, 61 to
70 – D and Others E.

Coding Section-
Output-
Program – 2
Objective- To understand the concept of nested if-else

Task- Write a Python script to find and display largest of three


integers. (Use nested if-else)

Coding Section-

Output-
Program – 3
Objective- To understand the concepts of while loop with if-else
statement.

Task- Write a menu driven Python script to calculate area of


triangle, area of rectangle, area of circle based on user choice.
(use if-else, while loop)

Coding Section-
Output-
Program – 4
Objective- To understand the concepts of simple & nested for() loop.

Task- Write a program to input the value of x and n and print the sum of
the following series:

• 1 + 𝑥 + 𝑥^2 + 𝑥^3 + 𝑥^4 + 𝑥^5+ . .. 𝑥^𝑛

• 1 − 𝑥 + 𝑥^2 – 𝑥^3 + 𝑥^4 – 𝑥^5+ . .. 𝑥^𝑛

• 𝑥 – 𝑥^2/ 2 + 𝑥^3/ 3 + 𝑥^4/ 4 – 𝑥^5/ 5 . .. 𝑥^𝑛/ 𝑛

• 𝑥 + 𝑥^2/ 2! – 𝑥^3/ 3! + 𝑥^4/ 4! – 𝑥^5/ 5! .. 𝑥^𝑛/ n!

Coding Section-
Output-
Program – 5
Objective- To understand the concepts of while() loop.

Task- Write a program to determine whether a number is a perfect number,


an Armstrong number or a palindrome.

Coding Section-
Output-
Program – 6
Objective- To understand the concepts of function and while()
loop

Task- Write a Python script to sum and display N terms of


Fibonacci Series using function. The 'N' should be passed to
function as parameter.
Coding section-
Output-
Program –7
Objective- To understand the concepts of for() loop, function with
parameter

Task- Write a Python script to print the table of a given number.


The given number should be passed to a function as parameter.
Coding section-

Output-
Program – 8
Objective- To understand the concepts of for() loop, function
parameters and return value

Task- Write a Python script to calculate the factorial of a given


number using function. The number should be passed as
parameter and function should return the value of factorial.

Coding section-

Output-
Program – 9
Objective- To understand the concept of string with function

Task- Write a Python script to count number of vowels, number of


digits, number of uppercase letters, number of lowercase letters
present in a string. (Use function)
Coding section-
Output-
Program – 10
Objective- To understand the concepts of for() loop, function
parameters and return value

Task- Write a Python script to check whether an entered string is


a palindrome or not. (Use function)

Coding section-
Output-
Program – 11
Objective- To understand the concept of list as parameter to a
function.

Task- Write a Python script to print largest and smallest element


present in a list without using min() and max() built in functions.
The list should be passed as parameter to a function.
Coding section-
Output-
Program – 12
Objective- To understand the concept of list as parameter to a
function.

Task- Write a Python script to swap adjacent elements of a list


using function. The list should be passed as a parameter to the
function.
Coding section-

Output-
Program – 13
Objective- To understand the concept of dictionary as an
argument to a function.

Task- Write a Python script to create a dictionary to store AQI (Air


quality index) for ten cities of India and display best and worst
city name based of AQI. Use Dictionary as an argument to a
function.
Coding section-
Output-
Program – 14
Objective- To understand the use of dictionary with string.

Task- Write a Python script to count frequency of each letter


present in string. (use dictionary to store counting with function)
Coding section-
Output-
Program – 15
Objective- To understand the concept of dictionary with function

Task- Write a Python script to store number of covid-19 patients


based on their countries, then display number of covid-19
patients country wise.(use dictionary and function) Use Country
name as key and value as number of covid-19 patients.

Coding section-
Output-
DATA FILES (TEXT FILES and BINARY FILES)

Program – 16
Objective- To understand the concept of open(), close(), reading of text
file using read() function and nested if-else.

Task- Write a Python script to count number of characters, number of


uppercase letters, number of lowercase letters, number of vowels, number of
digits, number of spaces and number of other characters present in disk file
'story.txt'.
Coding Section-

Text file (‘Story.txt’)-


Output-
Program – 17
Objective- To understand the concept of multiple files handing in
Python

Task- Write a Python script to replace all occurrence of 'he' with


'she' in a text file 'STORY.TXT'
Coding section-
Output-
Text file (‘.STORY.TXT’)-
Program – 18
Objective- To understand the concept of multiple files handing in
Python

Task- Assuming that a text file named TEXT1.TXT already


contains some text written into it, write a function named
vowel_words(), that reads the file TEXT1.TXT and creates a new
file named TEXT2.TXT, which shall contain only those words from
the file TEXT1.TXT which don’t start with an uppercase vowel (i.e.,
with ‘A’, ‘E’, ‘I’, ‘O’, ‘U’). For example, if the file TEXT1.TXT
contains Carry Umbrella and Overcoat When It rains. Then the
text file TEXT2.TXT shall contain Carry and When rains
Coding section-

Output-

Text files-
TEXT1.TXT

TEXT2.TXT
Program – 19
Objective- To understand the working of readlines() function.

Task- Write a function in PYTHON to count the number of lines


ending with a vowel from a text file 'STORY1.TXT'

Coding section-

Output and Text file (‘STORY1.TXT’)-


Program – 20
Objective- To understand the working of readline() function.

Task- Read a text file(story2.txt) line by line and display each


word separated by a #.

Coding section-

Output and Text file


(‘story2.TXT’)-
Program – 21
Objective- To understand the concept of binary file with
pickle.dump() and pickle.load() method.

Task- Given a binary file “STUDENT.DAT”, containing records of


the following type:

[Adm no, Name, Per] …. Where these three values are: Adm no –
Admission Number of student (integer), Name - Name of student
(string), Per – Marks percentage of student (float) Write a Python
script to write the details of students in a binary file. Also read
contents of the file “STUDENT.DAT” and display the details of
those students whose percentage is above 75.

Coding section-
Output and Binary file (‘STUDENTS.DAT’)-
Binary File-

Program – 22
Objective- To understand the concept of read/write/update/delete
records from a binary file using dictionary as record object.

Task- Write a menu driven program for the binary file ITEMS.DAT
storing the objects of following type: {"ID":integer, "GIFT":string,
"Cost":float}

i) To write the objects of above


type in binary file.

ii) To read and display all the


objects.

iii) To update an object for a given ID.

iv) To delete an object for a given ID.

Coding section-
Output-
This record got updated to-
Records in file after updating and deletion-

Binary file-
“GIFTS.DAT”
CSV Files
Program – 23

Objective- To understand the concept of csv.writer(),


csv.reader(), writerow() or writerows() functions of csv module .

Task- Write a menu driven program to read/write data in CSV


file(emp.csv) also display number of records in CSV file. Suppose
CSV file contain following data:
id, name, email, age, designation
1,John,[email protected],24,programmer
2,Bob,[email protected],34,designer
3,Mary,[email protected],43,sales
4,Raj Kumar, [email protected],34,data analysist
5,Kerry,[email protected],24,developer

Coding section-
Output-
emp.csv-
Program - 24

Objective- To understand the concept of csv.writer(), csv.reader(),


writerow() or writerows() functions of csv module.

Task- Write a Program to read CSV file(authors.csv) and display


the details those authors who have written their book in the year
1991. Suppose CSV file contain following data:
Programming language, Designed by, Appeared, Extension
Python, Guido van Rossum, 1991, .py
Java, James Gosling, 1995, .java
C++, Bjarne Stroustrup, 1985, .cpp
C, Yashwant Kanetkar, 1980, .c
Coding Section-

Output-

Authors.csv-
Program – 25

Objective- To understand the concept of csv.reader(), next(),


header in csv file.
Task- program to read and display CSV file(authors.csv) without
heading and avoid blank lines between records.

Coding section-

Output-

Authors.csv-
Data Structure

Program-26

Objective- To understand the concept of STACK(LIFO).

Task-To understand the concept of STACK(LIFO).


Coding Section-
Output-
SQL Statements
Program-27
Objective- To understand the use of create database, use, create
table with primary key, insert into, select with where and order by
clause.
Task- In a database 'Company' create a table 'Customer' of
following columns with appropriate datatypes and insert the
records:

Customer
ID Name Address Phone NoOfvisit
1 Ankit jain C-9, Yamuna Vihar, 9458795823 4
Delhi
2 Simranjeet G-89, Bandra, 9857589696 3
Mumbai
3 Sumedha H-90, Janakpuri, 7856987589 2
Madan Delhi
4 Simranjeet R-78, Worli, 9658758963 6
Mumbai
5 John T-90, California 9658758963 12

With reference to above table, write the SQL statements:


(i) To display customer name and address of all customers
living in Mumbai.

(ii) To display the details of all customer in descending


order of their names.
(iii) To name of those customer whose number of visits in
the range of 3 and 10.

(iv) To display Name of those customer whose phone is


empty.

(v) SELECT DISTINCT NAME FROM CUSTOMER WHERE


ID>=3;
(vi) SELECT COUNT(*) FROM CUSTOMER;

Coding Section-
Creating database company and table customer
Inserting values in Customer table

Q1

Q2
Q3

Q4

Q5

Q6
Program-28
Objective- To understand the use of create table with foreign
key, update, alter table and SQL joins.
Task- Create another table 'Bill' under 'company' database with
appropriate datatypes and insert the records.

Bill
BillNo Id Bill_Amoun
t
1 2 12500
2 1 15000
3 2 16000
4 3 25000
5 4 1400

With reference to above tables(Customer and Bill), write the SQL


statements:
(i)To display Cartesian product of Customer and Bill
tables.

(ii) To display customer name and bill amount of all


customers living in Delhi.

(iii)To display Equi-Join of Customer and Bill tables.

(iv) To display Natural Join of Customer and Bill tables.


(v) Increase the bill amount by 1000 of customers
having id as 1.
(vi) Add a new column "Remarks" of Varchar(20) in
remarks table.

(vii) Add Billno as primary in Bill table.

(viii) SELECT MAX(BILL_AMOUNT), MIN(BILL_AMOUNT)


FROM CUSTOMER, BILL WHERE CUSTOMER.ID =
BILL.ID ;

(ix) SELECT ID, SUM(BILL_AMOUNT) FROM BILL Group


by Id;

(x) 29. SELECT NAME, BILL_AMOUNT FROM CUSTOMER,


BILL WHERE CUSTOMER.ID=BILL.ID;
Coding Section- Creating table Bill under database
company
Q1-

Q2-
Q3-

Q4-

Q5-
Q6-

Q7-
Q8-

Q9-

Q10-
Program-29
Objevtive-To understand the use of create table with primary key, insert
into, select with where, like, between, order by clause, delete & aggregate
functions.

Task- In a database 'School' create a table "Teacher" with appropriate


datatypes and insert the records:

TI TName Subjec Gende Salary DOJ


D t r
10 Rakesh Comp. M 45000 2000-02-12
1 Sc
10 Smith Maths M 55000 2004-01-03
2
10 Sangeet History F 50000 2010—03-12
3 a
10 Simran Comp. F NULL 2018-10-02
4 Sc
10 Anil Maths M 56000 2010-12-01
5

With reference to above table write the SQL statements:


(i) To display Name, salary for those teachers who are teaching
maths.
(ii)To display Name of female teachers who teaches computer
science subject.
(iii)To display teachers name and date of join who teachers either
Computer science or History or English.
(iv) To display details of those teachers who have join in march
month.
(v) To set the salary as 40000 for those whose salary is not
decided.
(vi) Display the structure of teacher table.
(vii) Delete those records who have joined before 1st Jan. 2020.
(viii) SELECT SUBJECT, MAX(SALARY) FROM TEACHER GROUP BY
SUBJECT;
(ix) SELECT MIN(SALARY) FROM TEACHER WHERE GENDER='M';

(x)SELECT TNAME, SUBJECT FROM TEACHER WHERE SUBJECT LIKE


'%Sc.';

Coding Section-
Q1-

Q2-

Q3-

Q4-
Q5-

Q6-

Q7-
Q8-

Q9-

Q10-
Program-30
Objective-To understand the use of create table with primary
key, insert into, select with where, in, order by clause, equi-join &
aggregate functions.
Task- Create another table 'Student' under 'School' database with
appropriate datatypes and insert the records.
RNo SName Class TID
1 Ankur Gupta XI 101
2 Deepa Sharms XII 104
3 Ankit XI 102
4 Rahul Sharma XII 102
5 Raman Kumar XII 105

With reference to above tables, write the SQL statements:

(i)Add RNo as primary key in Student table.


(ii) To display student names having exactly five characters in
their length.
(iii) To display Name, salary for those teachers who are teaching
class XI.
(iv) To display name of those students who are taught by teacher
id as 102.
(v) To display Name of students and their class whose taught by
female teachers only.
(vi) To display teachers name, students name and class of student
with corresponding matching TID.
(vii) Modify the width of 'Sname' column as 25.
(viii) SELECT MAX(SALARY) FROM TEACHER WHERE GENDER='M';
(ix) SELECT SNAME, TID FROM STUDENT WHERE CLASS='XII'
ORDER BY SNAME DESC;
(x) SELECT TNAME, SUBJECT, SNAME FROM TEACHER, STUDENT
WHERE TEACHER.TID=STUDENT.TID AND CLASS='XI';

Coding section-
Q1-

Q2-

Q3-
Q4-

Q5-

Q6-
Q7-

Q8-

Q9-
Q10-
Program – 31
Objective- To understand the concept of mysql.connector,
connect(), cursor(), cursor.execute(), close() functions with 'create
databse', 'use', 'create table' commands of SQL.
Task-Write a Program to create a table 'EMP' under 'COMPANY'
database with following structure:
First_Name char(20) Not Null,
Last_Name char(20),
Age int(3)
Gender char(1)
Income Float(9,2)
DOJ date
Use MySQL database connectivity with Python.

Coding Section-
Program-32
Objective-To understand the concept of mysql.connector,
connect(), cursor(), cursor.execute(), commit(), close() functions
with 'use', 'insert into' commands of SQL.
Task-Write a program to insert at least 5 records in the table
created in previous program, also display its content on the
screen using MySQL database connectivity with Python.

Coding Section-
Output-
Program-33
Objective-To understand the concept of mysql.connector,
connect(), cursor(), cursor.execute(), close() functions with 'use',
'select' commands of SQL.
Task-Write a program to display those employee records who
have joined before 1st January, 2010 from 'EMP' using MySQL
database connectivity with Python. Also count number of such
employees.
Coding Section-
Output-

Program - 34
Objective-To understand the concept of mysql.connector,
connect(), cursor(), cursor.execute(), commit(), close() functions
with 'use', 'update' commands of SQL.
Task-Write a program to set date of join as 1st January, 2017 for
those employees whose date of join not entered, using MySQL
database connectivity with Python.
Coding Section-

Output-
Program – 35
Objective-To understand the concept of mysql.connector,
connect(), cursor(), cursor.execute(), commit(), close() functions
with 'use', 'delete' commands of SQL.
Task-Write a program to delete those records whose age more
than 60 years from 'EMP' table using MySQL database
connectivity with Python.
Coding Section-

You might also like