Project Cs(Computer Science)
Project Cs(Computer Science)
Public
School
Practical file- (2024-2025)
Computer science- (083)
15. A list, NList contains the following record as list elements: [City, Country,
distance from Delhi] Each of these records are nested together to form a
nested list. Write the following user-defined functions in Python to perform
the specified operations on the stack named travel.
(i) Push_element(NList): It takes the nested list as an argument
and pushes a list object containing name of the city and
country, which are not in India and the distance is less than
3500 km from Delhi.
(ii) Pop_element(): It pops the objects from the stack and
displays them. Also, the function should display “Stack
Empty” when there are no elements in the stack.
16. Given a Dictionary Stu_dict containing marks of students for three test-
series in the form Stu_ID:(TS1, TS2, TS3) as key-value pairs. Write a
Python program with the following user-defined functions to perform the
specified operations on a stack named Stu_Stk
(i) Push_elements(Stu_Stk, Stu_dict) : It allows pushing IDs of
those students, from the dictionary Stu_dict into the stack
Stu_Stk, who have scored more than or equal to 80 marks in
the TS3 Test.
(ii) Pop_elements(Stu_Stk): It removes all elements present
inside the stack in LIFO order and prints them. Also, the
function displays 'Stack Empty' when there are no elements
in the stack.
Call both functions to execute queries.
Output:
Practical-2
Aim: Write a program to input a character and to print
whether a given character is an alphabet, digit or any other
character.
Source Code:
Output:
Practical-3
Aim:Write a menu-driven Python Program to
perform Arithmetic operations (+,-*,/) based on
the user’s choice.
Source Code:
Output:
Practical-4
Aim: Write a Python Program to display the Fibonacci
Series up to ‘n’ numbers.
Source Code:
Output:
Practical-5
Aim: Write a menu-driven Python Program to find
factorial and sum of list of numbers using a function.
Source code:
Output:
Practical-6
Aim: To write a function rev number (num) that
accepts a number as an argument and returns the
reverse number.
Source Code:
Output:
Practical-7
Aim: Write a function countNow(PLACES) in
Python, that takes the dictionary, PLACES as an
argument and displays the names (in uppercase)of the
places whose names are longer than 5 characters.
Source Code:
Output:
Practical-8
Aim: Write a function, lenWords(STRING), that
takes a string as an argument and returns a tuple
containing length of each word of a string.
Source Code:
Output:
Practical-9
Aim: To write a Python program to generate random
number between 1 to 6 to simulate the dice.
Source Code:
Output:
Practical-10
Aim: Write a function dispBook(BOOKS) in Python,
that takes a dictionary BOOKS as an argument and
displays the names in uppercase of those books whose
name starts with a consonant.
Source Code:
Output:
Practical-11
Aim: Write a Python Program containing a function
FindWord(STRING, SEARCH), that accepts two
arguments: STRING and SEARCH, and prints the
count of occurrence of SEARCH in STRING. Write
appropriate statements to call the function.
Source Code:
Output:
Practical-12
Aim: Write a function in Python PUSH(Arr), where Arr is a
list of numbers. From this list push all numbers divisible by 5
into a stack implemented by using a list. Display the stack if it
has at least one element, otherwise, display appropriate error
message.
Source Code:
Output:
Practical-13
Aim: To write a Python program to implement Stack
using a list data structure, to perform the following
operations:
(i) To Push an object containing Doc_ID and Doc_name of doctors specialising
in "ENT" to the stack.
(ii) To Pop the objects from the stack and display them.
(iii) To display the elements of the stack (after performing PUSH or POP)
Source Code:
Output:
Practical-14
Aim: To Write a program, with separate user-defined
functions to perform the following operations:
(i) To Create a function Push(Stk,D) Where Stack is an
empty list and D is Dictionary of Items. from this
Dictionary Push the keys (name of the student) into
a stack, where the corresponding value (marks) is
greater than 70.
(ii) To Create a Function Pop(Stk) , where Stk is a
Stack implemented by a list of student names. The
function returns the items deleted from the stack.
(iii) To display the elements of the stack (after
performing PUSH or POP).
Source Code:
Output:
Practical-15
Aim: A list, NList contains the following record as list
elements: [City, Country, distance from Delhi] Each of these
records are nested together to form a nested list. Write the
following user-defined functions in Python to perform the
specified operations on the stack named travel.
(i) Push_element(NList): It takes the nested list as an
argument and pushes a list object containing name
of the city and country, which are not in India and
the distance is less than 3500 km from Delhi.
(ii) Pop_element(): It pops the objects from the stack
and displays them. Also, the function should display
“Stack Empty” when there are no elements in the
stack.
Source Code:
Output:
Practical-16
Aim: Given a Dictionary Stu_dict containing marks of
students for three test-series in the form Stu_ID:(TS1, TS2,
TS3) as key-value pairs. Write a Python program with the
following user-defined functions to perform the specified
operations on a stack named Stu_Stk
(i) Push_elements(Stu_Stk, Stu_dict) : It allows
pushing IDs of those students, from the dictionary
Stu_dict into the stack Stu_Stk, who have scored
more than or equal to 80 marks in the TS3 Test.
(ii) Pop_elements(Stu_Stk): It removes all elements
present inside the stack in LIFO order and prints
them. Also, the function displays 'Stack Empty'
when there are no elements in the stack.
Call both functions to execute queries.
Source Code:
Output:
Practical-17
Aim: W.A.P. to Check if a number is positive,
negative, or zero.
Source Code:
Output:
Practical-18
Aim: W.A.P. to print all even numbers up to a
given number using a for loop.
Source Code:
Output:
Practical-19
Aim: W.A.P. to find the factorial of a number
using a while loop.
Source Code:
Output:
Practical-20
Aim: W.A.P. to check if a given year is a leap
year.
Source Code:
Output:
Practical-21
Aim: W.A.P. to find the sum of all numbers in a
given range.
Source Code:
Output:
Practical-22
Aim: W.A.P to Find the largest number in a list.
Source Code:
Output:
Practical-23
Aim: W.A.P. to count the occurrences of an
element in a tuple.
Source Code:
Output:
Practical-24
Aim: W.A.P. to create a dictionary from user
input and display it.
Source Code:
Output:
Practical-25
Aim: W.A.P. to remove an element from a list by
value.
Source Code:
Output:
Practical-26
Aim: W.A.P. to merge two dictionaries.
Source Code:
Output:
Practical-27
Aim: W.A.F. to check if a string is a palindrome.
Source Code:
Output:
Practical-28
Aim: W.A.F. to calculate the power of a number.
Source Code:
Output:
Practical-29
Aim: W.A.F. to convert Celsius to Fahrenheit.
Source Code:
Output:
Practical-30
Aim: W.A.F. to calculate the sum of digits of a
number.
Source Code:
Output:
Practical-31
Aim: W.A.F.. to find the LCM (Least Common
Multiple) of two numbers.
Source Code:
Output:
Practical-32
Aim: W.A.F. to implement a stack using a list
with push and pop operations.
Source Code:
Output:
Practical-33
Aim: W.A.F. to Check if the stack is empty.
Source Code:
Output:
Practical-34
Aim: W.A.F. to peek at the top element of the
stack.
Source Code:
Output:
Practical-35
Aim: W.A.F. to get the size of the stack.
Source Code:
Output:
Practical-36
Aim: W.A.F. to display all elements in the stack.
Source Code:
Output:
Practical-37
Aim: Write a function in python to count the
number of lines in a text file ‘Country.txt’ which is
starting with an alphabet ‘W’ or ‘H’.
Source Code:
Output:
Practical-38
Aim: Write a user defined function countwords()
to display the total number of words present in the
file from a text file “Quotes.Txt”.
Source Code:
Output:
Practical-39
Aim: Write a function COUNT_AND () in Python
to read the text file “STORY.TXT” and count the
number of times “AND” occurs in the file.
(include AND/and/And in the counting)
Source Code:
Output:
Practical-40
Aim: Write a function DISPLAYWORDS() in
Python to display the count of words starting with
“t” or “T” in a text file ‘STORY.TXT’.
Source Code:
Output:
Practical-41
Aim: Write a function that counts and displays the
number of 5 letter words in a text file
“Sample.txt”.
Source Code:
Output:
Practical-42
Aim: Write a function to display those lines
which start with the letter “G” from the text file
“MyNotes.txt”.
Source Code:
Output:
Practical-43
Aim: Write a function in Python to read lines from
file “POEM.txt” and display all those words,
which has two characters in it.
Source Code:
Output:
Practical-44
Aim: Write a function COUNT() in Python to
read contents from file “REPEATED.TXT”, to
count and display the occurrence of the word
“Catholic” or “mother”.
Source Code:
Output:
Practical-45
Aim: Write a function COUNTLINES_ET() in
python to read lines from a text file
REPORT.TXT, and COUNT those lines which are
starting either with ‘E’ and starting with ‘T’
respectively. And display the total count
separately.
Source Code:
Output:
Practical-46
Aim: Write a method/function SHOW_TODO() in
Python to read contents from a text file ABC.TXT
and display those lines which have occurrence of
the word ‘TO’ or ‘DO’.
Source Code:
Output:
Practical-47
Aim: Write a function in Python that counts the
number of “Me” or “My” words present in a text
file “STORY.TXT”.
Source Code:
Output:
Practical-48
Aim: Write a function AMCount() in Python,
which should read each character of a text file
STORY.TXT, should count and display the
occurrences of alphabets A and M (including small
cases a and m too).
Source Code:
Output:
Practical-49
Aim: Write a function in Python that displays the
number of lines starting with ‘H’ in the file
“para.txt”.
Source Code:
Output:
Practical-50
Aim: Write a function countmy() in Python to
read file Data.txt and count the number of times
“my” occur in the file.
Source Code:
Output:
Practical-51
Aim: Write a Python program to find the number
of lines in a text file ‘abc.txt’.
Source Code:
Output:
Practical-52
Aim: Write a Python program to count the word
“if “ in a text file ‘abc.txt’.
Source Code:
Output:
Practical-53
Aim: Write a method in Python to read lines from
a text file DIARY.TXT and display those lines
which start with the alphabets P.
Source Code:
Output:
Practical-54
Aim: Write a method/function ISTOUPCOUNT()
in Python to read contents from a text file
WRITER.TXT, to count and display the
occurrence of the word ‘‘IS’’ or ‘‘TO’’ or ‘‘UP’’.
Source Code:
Output:
Practical-55
Aim: Write a code in Python that counts the
number of “The” or “This” words present in a text
file “MY_TEXT_FILE.TXT”.
Source Code:
Output:
Practical-56
Aim: Write a function VowelCount() in Python,
which should read each character of a text file
MY_TEXT_FILE.TXT, should count and display
the occurrence of alphabets vowels.
Source Code:
Output:
Practical-57
Aim: Write a function filter(oldfile, newfile) that
copies all the lines of a text file “source.txt” onto
“target.txt” except those lines which starts with
“@” sign.
Source Code:
Output:
Practical-58
Aim: W.a.c to check name, mode of file ,whether
file is closed or not and show encoding format.
Source Code:
Output:
Practical-59
Aim: A binary file “student.dat” has structure [rollno, name, marks].
(i) Write a user defined function insertRec() to input data for a
student and add to student.dat.
(ii) Write a function searchRollNo( r ) in Python which accepts
the student’s rollno as parameter and searches the record in
the file “student.dat” and shows the details of student i.e.
rollno, name and marks (if found) otherwise shows the message
as ‘No record found’.
Source Code:
Output:
Practical-60
Aim: A binary file “emp.DAT” has structure [EID, Ename,
designation,salary].
Source Code:
Output:
Practical-61
Aim: A binary file “Book.dat” has structure [BookNo, Book_Name,
Author, Price]
(i) Write a user defined function CreateFile() to input data for a record
and add to “Book.dat”
Source Code:
Output:
Practical-62
Aim: A binary file student.dat has structure
[rollno,name,class,percentage].
Write a program to updating a record in the file
requires roll number to be fetched from the user whose
name is to be updated
Source Code:
Output:
Practical-63
Aim: Create a file rec.csv with the structure [emp
id, emp name, salary], then write the following
functions:
1. Add(): To add details of employees.
2. CRec(): Count and display the number of records.
Source Code:
Output:
Practical-64
Aim: Write a program to copy data from file.csv
to copy.csv.
Source Code:
Output:
Practical-65
Output:
Output:
Output:
Query 7: Write a query to update student contact
number, teacher's subject in Students , Teaches
tables respectively.
O
utput:
Query 8: Write a query to view all classes with
teachers.
Output:
Output:
Output:
Query 13: Write a query to find students in grade
9 who are 15 years old.
Output:
O
utput:
Query 15: Write a query to List teachers teaching
specific subjects.
Output:
O
utput:
Outpu
t:
Output:
Ou
tput:
Outp
ut:
Output:
Query 23: Write a query to add a new column.
Ou
tput:
Output:
Out
put:
Practical-66
Aim: Write a program to intrgrate MYSQL
with PYTHON (creating database and
table).
Source Code:
Output:
Practical-67
Aim: Write a program to intrgrate MYSQL
with PYTHON (inserting records and
displaying records).
Source Code:
Output:
Practical-68
Aim: Write a program to intrgrate MYSQL with
PYTHON (searching records and displaying
records).
Source Code:
Output:
Practical-69
Aim: Write a program to intrgrate MYSQL with
PYTHON (updating records and displaying
records).
Source Code:
Output: