Moksh Practical File1
Moksh Practical File1
NAME:MOKSH
CLASS: XII-A
ROLL NO: 21
SCHOOL: KENDRIYA VIDYALAYA SAINIK VIHAR
1. Write a single loop to display all the contents of a text file output.txt after
removing leading and trailing WHITESPACES
O/P:
if the file contains 'GOOD' before execution, what will be the content of the file after
execution of the code.
Ans) BYE
- Text file
(ii) Fill in the blank1 with statement to write "abc" in the file "mydata"
- f1.write(“abc”)
5. In which of the following file modes the existing data of the file will not be lost?
i) rb
ii) w
iii) a+b
iv) wb+
v) r+
vi) ab
vii) w+b
viii)wb
ix) w+
Ans) rb, a+b, r+, ab
7 Suppose a file name test1.txt store alphabets in it then what is the output of the
following code
f1=open("test1.txt")
size=len(f1.read())
print(f1.read(5))
Ans)The output will be an empty string because the file pointer is already at the end
after the first f1.read().
8.Write a user-defined function in Python that displays the number of lines starting
with 'H' in the file para.txt.
INPUT:
OUTPUT:
CONTENT OF FILE:
9.Write a function countmy() in Python to read the text file DATA.TXT and count the
number of times "my" occurs in the file.
INPUT:
OUTPUT:
INPUT:
OUTPUT:
CONTENT OF FILE:
11.write a method in python to read lines from a text file MYNOTES.TXT and display
those lines which start with alphabets 'K'
INPUT:
OUTPUT:
12.write a program to display all the records in a file along with line/record number.
INPUT:
OUTPUT:
14.Write a program that copies a text file "source.txt" onto "target.txt" barring the
lines starting with @ sign.
INPUT:
OUTPUT:
CONTENT OF SOURCE.TXT:
CONTENT OF TARGET.TXT:
15. 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
i)
INPUT:
OUTPUT:
CONTENT OF FILE:
ii)
INPUT:
OUTPUT:
i. Bus Number
ii. Bus route
iii. Bus Destination
INPUT:
OUTPUT:
18. Write a function addrec() in Python to add more new records at the bottom of a
binary file “STUDENT.dat”, assuming the binary file is containing the following
structure :
INPUT:
OUPUT:
INPUT:
OUTPUT:
OUTPUT:
21.Write a function countrec(sport name) in Python which accepts the name of sport
as parameter and count and displays the coach name of a sport which is passed as
argument from the binary file “sport.dat”. Structure of record in a file is given below
[sport name, coach name]
OUTPUT:
22.. A binary file “salary.DAT” has structure [employee id, employee name, salary].
Write a function countrec() in Python that would read contents of the file “salary.DAT”
and display the details of those employees whose salary is above 20000.
23.Amit is a monitor of class XII-A and he stored the record of all the students of his
class in a file named “class.dat”. Structure of the record is [roll number, name,
percentage]. His computer teacher has assigned the following duty to Amit.
Write a function remcount( ) to count the number of students who need remedial
class (student who scored less than 40 percent)
INPUT:
OUTPUT:
25.How to print the following data for cust.csv in tabular form using python code?
INPUT:
OUTPUT:
CONTENT OF CSV FILE:
INPUT:
OUTPUT:
CONTENT OF THE FILE:
28.Write a python program to search an element in a list and display the frequency of
elements present in the list and their location using Linear search by using a user
defined function. [List and search element should be entered by user]
INPUT:
OUTPUT:
29.Write a python program to search an element in a list and display the frequency of
elements present in list and their location using binary search by using a user defined
function. [List and search element should be entered by user]
INPUT:
OUTPUT:
30.Write a python program to pass a list to a function and double the odd values and
half even values of a list and display list elements after changing.
INPUT:
OUTPUT:
31.Write a Python program input n numbers in tuple and pass it to function to count
how many even and odd numbers are entered.
INPUT:
OUTPUT:
32.Write a Python program to function with key and value, and update value at that
key in the dictionary entered by the user.
INPUT:
OUTPUT:
33.Write a Python program to pass a string to a function and count how many vowels
present in the string.
INPUT:
OUTPUT:
34.Write a Python program to generator(Random Number) that generates random
numbers between 1 and 6 (simulates a dice) using a user defined function.
INPUT:
OUTPUT:
INPUT:
OUTPUT:
INPUT:
OUTPUT:
37.Write a python program to read and display file content line by line with each word
separated by #.
INPUT:
OUTPUT:
38.Write a python program to remove all the lines that contain the character ‘a’ in a
file and write it to another file.
INPUT:
OUTPUT:
39.Write a python program to read characters from keyboard one by one, all lower
case letters gets stored inside a file “LOWER”, all uppercase letters gets stored inside
a file “UPPER”, and all other characters get stored inside “OTHERS”
INPUT:
OUTPUT:
40.Write a python program to create a binary file with name and roll number. Search
for a given roll number and display name, if not found display appropriate message
INPUT:
OUTPUT:
41. Write a python program to create a binary file with roll number, name and
marks, input a roll number and update the marks.
INPUT:
OUTPUT:
42. Write a python program to create a CSV file with empid, name and mobile
no. and search empid, update the record and display the records.
INPUT:
OUTPUT:
43.Write a Python program to create Lpush( ) and Lpop( ) functions to do push and
pop operations on a stack using a list e.g. take a student information and push and
pop the details.
INPUT:
OUTPUT:
44. Create a student table and insert data. Implement the following SQL commands
on the student table:
ALTER table to add new attributes / modify data type / drop attribute
INPUT:-
use
studentdb;
Database
changed
CREATING
TABLE
create table
student (roll int
not null,
studentname varchar(30)
not null, class char(5) not
null,
OUTPUT:
INSERTING VALUE
OUTPUT:
UPDATING VALUE
desc student;
desc student
ORDER BY COMMAND
AVERAGE COMMAND
45.Integrate SQL with Python by importing the MySQL module record of employees
and display the record.
INPUT:
OUTPUT:
INPUT:
OUTPUT:
47.Integrate SQL with Python by importing the MySQL module to search a student
using rollno, update the record.
INPUT:
OUTPUT:
48.Integrate SQL with Python by importing the MySQL module to search a student
using rollno, delete the record.
INPUT:
OUTPUT:
49.Take a sample of ten phishing e-mails (or any text file) and find most commonly
occurring word(s)
INPUT:
OUTPUT: