Class XII Computer Science
Practical
Q1: Read a text file line by line and replace the space character
between words with # symbol.
CODE:
OUTPUT:
Before:
After:
Q2: Read a text file and display the number of
vowels/consonants/uppercase/lowercase characters in the file.
CODE:
OUTPUT:
Q3: Remove all the lines that contain the word 'are' from a file and
write those lines to another file.
CODE:
OUTPUT:
Q4: Write a program in Python to get student details (Rollno, Name
and Marks) for multiple students from the user and create a CSV file
by writing all the student details in one go. Also read and display the
data of CSV file.
CODE:
OUTPUT:
Q5: Create a binary file with roll number, name and marks. Input a
roll number and update the marks.
CODE:
OUTPUT:
Q6: Write a random number generator that generates random
numbers between 1 and 6 (simulates a dice).
CODE:
OUTPUT:
Q7: Write a Python program to implement a stack using list.
CODE:
OUTPUT:
Q8: Create a CSV file by entering user-id and password, read and
search the password for given userid.
CODE:
OUTPUT:
Q9: To secure your account, whether it be an email,online bank
account or any other account, it is important that we use
authentication. Use your programming expertise to create a program
using user defined function named login that accepts userid and
password as parameters (login(uid,pwd)) that displays a message
“account blocked” in case of three wrong attempts. The login is
successful if the user enters user ID as "ADMIN" and password as
"St0rE@1". On successful login, display a message “login successful”.
CODE:
OUTPUT:
Q10: Take a look at the series below: 1, 1, 2, 3, 5, 8, 13, 21, 34, 55… To
form the pattern, start by writing 1 and 1. Add them together to get 2.
Add the last two numbers: 1+2 = 3, continue adding the previous two
numbers to find the next number in the series. These numbers make
up the famed Fibonacci sequence: previous two numbers are added to
get the immediate new number.
CODE:
OUTPUT:
Q11: Create a menu driven program using user defined functions to
implement a calculator that performsthe following:
a) Basic arithmetic operations(+,-,*,/)
b) log10(x),sin(x),cos(x)
CODE:
OUTPUT:
Q12: Write a program that creates a GK quiz consisting of any five
questions of your choice. The questions should be displayed randomly.
Create a user defined function score() to calculate the score of the quiz
and another user defined function remark (scorevalue) that accepts
the final score to display remarks as follows:
CODE:
OUTPUT:
Q13: A school has created a dictionary containing top players and
their runs as key value pairs of cricket team. Write a program, with
separate user defined function to perform the following operations:
a) Push the name of the players(eys) of the dictionary into a stack,
where the corresponding runs (value) is greater than 49.
b) Pop and display the content of the stack. For example, If dictionary
has the following values:
Data={‘Rohan’:40,’Rihaan’:55,’Tejas’:80,’Ajay’:90} The output should be:
Ajay,Tejas, Rihaan
CODE:
OUTPUT:
Q14: A binary file [Link] has structure [BookNo, BookName, Author]
so:
a) Write a user defined function FileData() to input data for a record
and add to [Link].
b) Write a function CountData(Author) in Python which accepts the
AuthorName as parameter and count and return number of books by
the given author are stored in the binary file [Link].
CODE:
OUTPUT:
Q15: A list contains following record of customer: [Customer_Name,
Room_Type].
Write the following user defined functions to perform the given
operations on the stack named ‘Hotel’:
a) Push_Cust()- To push customers’ names of those customers who are
staying in ‘Delux’ Room Type.
b) Pop_Cust()- To pop the names of customers from the stack and
display them . Also, display “Underflow” when there are no customers
in the stack.
CODE:
OUTPUT:
Q16: Write a function count_char() that reads a file named “[Link]”
counts the number of times character “a” or “A” appears in it.
CODE:
OUTPUT:
Q17: Write a function called length_line() that reads a file named
“[Link]” and displays the length of each line present in the text file.
CODE:
OUTPUT:
Q18: Write a function count_word() that reads a text file named
“[Link]” and returns the number of times word “ the” exists.
CODE:
OUTPUT:
Q19: Write a function count Words (in Python to count the words
ending with a digit in a text file "[Link]".
Example: If the file content is as follows:
On seat2 VIP1 will sit and
On seat1 VIP2 will be sitting
Output will be: 4
CODE:
OUTPUT:
Q20: Write a method/function DISPLAYWORDS() in python to read
lines from a text file [Link], and display those words, which are
less than 4 characters.
CODE:
OUTPUT: