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

Project Cs(Computer Science)

This document is a practical file for a Computer Science course (083) for the academic year 2024-2025, submitted by a student named Farhan Samar. It contains a comprehensive index of programming tasks and functions to be implemented in Python, covering various topics such as prime number checking, arithmetic operations, stack implementation, and file handling. Each practical includes an aim, source code, and expected output for the respective programming tasks.

Uploaded by

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

Project Cs(Computer Science)

This document is a practical file for a Computer Science course (083) for the academic year 2024-2025, submitted by a student named Farhan Samar. It contains a comprehensive index of programming tasks and functions to be implemented in Python, covering various topics such as prime number checking, arithmetic operations, stack implementation, and file handling. Each practical includes an aim, source code, and expected output for the respective programming tasks.

Uploaded by

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

Apex

Public
School
Practical file- (2024-2025)
Computer science- (083)

Submitted To: Submitted By:


Mrs. Sapna Anand Name: Farhan Samar
PGT(C.S.) Class: XII-A (Science)
Roll No: 35
INDEX
S. No. Program List
1. Write a Function Prime(n) in Python to check whether a number is Prime.

2. Write a program to input a character and to print whether a given character


is an alphabet, digit or any other character.
3. Write a menu-driven Python Program to perform Arithmetic operations (+,-
*,/) based on the user’s choice.
4. Write a Python Program to display the Fibonacci Series up to ‘n’ numbers.
5. Write a menu-driven Python Program to find factorial and sum of list of
numbers using a function.
6. To write a function rev number (num) that accepts a number as an argument
and returns the reverse number.
7. 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.
8. Write a function, lenWords(STRING), that takes a string as an argument
and returns a tuple containing length of each word of a string.
9. To write a Python program to generate random number between 1 to 6 to
simulate the dice.
10. 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.
11. 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.
12. 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.
13. 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)

14. 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).

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.

17. W.A.P to check if a number is positive, negative, or zero.


18. W.A.P. to print all even numbers up to a given number using a for loop.
19. W.A.P. to find the factorial of a number using a while loop.
20. W.A.P. to check if a given year is a leap year.
21. W.A.P. to find the sum of all numbers in a given range.
22. W.A.P to Find the largest number in a list.
23. W.A.P. to count the occurrences of an element in a tuple.
24. W.A.P. to create a dictionary from user input and display it.
25. W.A.P. to remove an element from a list by value.
26. W.A.P. to merge two dictionaries.
27. W.A.F. to check if a string is a palindrome.
28. W.A.F. to calculate the power of a number.
29. W.A.F. to convert Celsius to Fahrenheit.
30. W.A.F. to calculate the sum of digits of a number.
31. W.A.F.. to find the LCM (Least Common Multiple) of two numbers.
32. W.A.F. to implement a stack using a list with push and pop operations.
33. W.A.F. to Check if the stack is empty.
34. W.A.F. to peek at the top element of the stack.
35. W.A.F. to get the size of the stack.
36. W.A.F. to display all elements in the stack.
37. 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’.
38. Write a user defined function countwords() to display the total number of words
present in the file from a text file “Quotes.Txt”.
39. 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)
40. Write a function DISPLAYWORDS() in Python to display the count of words
starting with “t” or “T” in a text file ‘STORY.TXT’.
41. Write a function that counts and displays the number of 5 letter words in a text file
“Sample.txt”.
42. Write a function to display those lines which start with the letter “G” from the text
file “MyNotes.txt”.
43. Write a function in Python to read lines from file “POEM.txt” and display all
those words, which has two characters in it.
44. 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”.
45. 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.
46. 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’.
47. Write a function in Python that counts the number of “Me” or “My” words present
in a text file “STORY.TXT”.
48. 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).
49. Write a function in Python that displays the number of lines starting with ‘H’ in
the file “para.txt”.
50. Write a function countmy() in Python to read file Data.txt and count the number
of times “my” occur in the file.
51. Write a Python program to find the number of lines in a text file ‘abc.txt’.
52. Write a code in Python that counts the number of “The” or “This” words present
in a text file “MY_TEXT_FILE.TXT”.
53. Write a method in Python to read lines from a text file DIARY.TXT and display
those lines which start with the alphabets P.
54. 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’’.
55. Write a code in Python that counts the number of “The” or “This” words present
in a text file “MY_TEXT_FILE.TXT”
56. 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
Practical-1
Aim: Write a Function Prime(n) in Python to
check whether a number is Prime.
Source Code:

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].

(i) Write a function to add more records of employees in existing file


emp.dat.
(ii) Write a function Show() in Python that would read detail of
employee from file “emp.dat” and display the details of those
employee whose designation is “Salesman”.

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”

(ii) Write a function CountRec(Author) in Python which accepts the


Author name as parameter and count and return number of books by the
given Author are stored in the binary file “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

Aim: Write SQL Commands.


Query 1: Write a query to create a database.

Output:

Query 2: Write a query to open database.

Output:

Query 3: Write a query to create tables (Students,


Teachers, Classes, Enrollments).
Output:

Query 4: Write a query to show list of tables in


SchoolDB database.
Output:

Query 5: Write a query to insert data into tables


(Students, Teachers, Classes, Enrollments).
Output:

Query 6: Write a query to view all the details of


Students, Teachers, Classes, Enrollments tables
respectively.

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:

Query 9: Write a query to view all details of


enrollment with students details.
Output:

Query 10: Write a query to Search for a Teacher


by Name.

Output:

Query 11: Write a query to get details of students


enrolled in 10.
Output:

Query 12: Write a query to find teacher teaching


Mathematics or Science.

Output:
Query 13: Write a query to find students in grade
9 who are 15 years old.

Output:

Query 14: Write a query to find Fetch the first 5


students alphabetically by name.

O
utput:
Query 15: Write a query to List teachers teaching
specific subjects.

Output:

Query 16: Write a query to find students whose


age is between 12 and 15.

O
utput:

Query 17: Write a query to find students whose


name starts with “A”.

Outpu
t:

Query 18: Write a query to find teachers whose


subject contains "Math".
Output:

Query 19: Write a query to know all teachers who


teach Math, Science, or English.

Output:

Query 20: Write a query to creates an index on


the name column in the teachers table to improve
query performance.

Ou
tput:

Query 21: Write a query to verify that the index


was created.

Outp
ut:

Query 22: Write a query to index


idx_teacher_name from the teachers table.

Output:
Query 23: Write a query to add a new column.

Ou
tput:

Query 24: Write a query to add multiple columns.

Output:

Query 25: Write a query to show table(students)


structure.
Outpu
t:

Query 26: Write a query to add a PRIMARY


KEY(book_id) in books store table.

Out
put:

Query 27: Write a query to delete a database


name TestDB.
Ou
tput:

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:

You might also like