0% found this document useful (0 votes)
28 views50 pages

Cs Practical Revised

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
28 views50 pages

Cs Practical Revised

Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 50

DELHI PUBLIC SCHOOL ,GWALIOR

Submitted by:- Kshitij Choudhary


XII-C
Certificate

This is certified that Kshitij Choudhary of class XII


has successfully completed the Computer Science
Practical under my guidance in the academic
session 2024-25.

He has taken proper care and shown utmost


sincerity in completing his practicals.

I certify that this practical skill is up to my expectations


and as per the guidelines issued by the Central Board of
Secondary Education.

Mr. Ajay Tomar

(PGT Computer Science)


ACKNOWLEDGEMENT

I would like to express my deep sense of Thanks and


Gratitude to my Computer Science Educator Mr.
Ajay Tomar for guiding me as well as motivating me
through the course of the practicals. He always
evinced keen interest in my work. His constructive
and constant motivation helped me in successfully
completing my practicals.

My sincere thanks go to Ms. Gayatri Shrivastava ,


the Principal of our school for extending every
possible support and environment for completing
my Computer Science practicals.

Kshitij Choudhary

XII-C
Program:-1

Write a Python Program to find sum of two


numbers

Source Code:-

Output
Program:- 2

Write a python program to find whether the


given no. is prime no.

Source Code:-

Output
Program 3:-

Write a program to find whether the number is


even or odd

Source Code:-

Output
Program 3:-

Write a program to create a menu driven


program to perform arithmetic operations

Source Code:-

Output
Program 4:-

Write a program swap values of two variables


without use of third variable.

Source Code:-

Output
Program 5:-

Write a program to generate random number


between 1 to 6 to create a dice

Source Code:-

Output
Program 6:-

Write a program to check if the given number is a


palindrome or not.

Source Code:-

Output
Program 7:-

Write a program to calculate perimeter and area


of rectangle

Source Code:-

Output
Program 8:-

Write a program to How to check if a given


number is Fibonacci number?

Source Code:-

Output
Program 9:-

Write a program to convert degree celsius to


degree fahrenheit

Source Code:-

Output
Program 10:-

Write a program to find whether the given year


is leap year or not

Source Code:-

Output
Program 11:-

Write a program to find root of quadratic


equation

Source Code:-

Output
Program 12:-

Write a program to make the following sequence

12

123:-

Source Code:-

Output
Program 13:-

Write a program to print following pattern

333

22

1
Source Code:-

Output
Program 14:-

Write a program to HCF of two numbers

Source Code:-

Output
Program 15:-

Write a program to make pyramid using “*”

Source Code:-

Output
Program 16:-

Write a program to copy contents of first file to other.

Source Code:-

Output
Program 17:

Write a program to count number of frequencies of a


word in a text file and display it.

Source Code:-

Output
Program 18:

Write a python program to count number of vowels,


lines and characters from text stored in a file and display
it.

Source Code:-

Output
Program 19:

Write a program to read contents from a text file and


show it line wise on screen.

Source Code:-

Output
Program 20:-

Write a program to count number of times B and S


appear in file F2.txt.

Source Code:-

Output
Program 20:
Aditi has used a text editing software to type some text.
After saving the article as WORDS.TXT, she realised that
she has wrongly typed alphabet b in place of alphabet i
everywhere in the article.
Write a function definition for bTOi() in Python that
would display the corrected version of entire content of
the file WORDS.TXT with all the alphabets “b" to be
displayed as an alphabet “i" on screen.
Note: Assuming that WORD.TXT does not contain any b
alphabet otherwise.

Source Code:-

Output
Program 21:-

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
Program 22:-

Write a function that counts and display the number of


5 letter words in a text file “Sample.txt”

Source Code:-

Output
Program 23:-

Write a function that counts and display the number of 5


letter words in a text file “Sample.txt”.

Source Code:-

Output
Program 24:-

Write a function that counts and display the number of


5 letter words in a text file “Sample.txt”

Source Code:-

Output
Program 25:-

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
MySQL Query 1:-

select * from cars where type='F1 Car’;

select distinct type from cars;


MySQL Query 2:-

Select * from employee where desig=‘programmer’

Select * from employee where salary>=100000


MySQL Query 3:-

(i) To display the details of those Clients whose city is


Delhi
(ii) To display the details of Products whose Price is in the
range of 50 to 100 (both values included).

ANS:-
i) SELECT * FROM CLIENT WHERE City="Delhi";

(ii) SELECT * FROM PRODUCT WHERE Price BETWEEN 50


and 100;
MySQL Query 4:-

(i) To display details of all models in the Model table in


ascending order of Date Of Manufacture

(ii) To display details of those models manufactured in


2011 and whose Cost is below 2000.

ANS:-
i. SELECT * FROM Model ORDER BY
DateOfManufacture;

ii. SELECT * FROM Model WHERE year


(DateOfManufacture) = 2011 AND Cost < 2000;
MySQL Query 5:-

(i) Display the Maximum Interest from Loans table.

(ii) Display the count of all loan holders whose name


ends with 'Sharma'.

ANS:-
i. SELECT MAX(Interest) FROM LOANS;

ii. SELECT COUNT(*) FROM LOANS WHERE Cust Name


LIKE '%Sharma';
MySQL Query 6:-

QUES:-

i) To display CNO, CNAME, TRAVELDATE from the table TRAVEL in


descending order of CNO.

ii) To display the CNAME of all customers from the table TRAVEL who are
travelling by vechicle with code Vo1 or Vo2.

ANS:-

i) SELECT CNO , CNAME, TRAVELDATE FROM TRAVEL ORDER BY CNO


DESC;

ii) SELECT CNAME FROM TRAVEL VCODE IN (‘V01’, ‘V02’);


MySQL Query 7:-

QUES:-

i) To display NO, NAME, TDATE from the table TRIP in descending


order of NO.

ii) To display the NAME of the drivers from the table TRIP who are
traveling by transport vehicle with code 101 or 103.

ANS:-

i) SELECT NO, NAME, TDATE FROM TRIP

ORDER BY NO;

ii) SELECT NAME FROM TRIP WHERE TCODE = 101 OR TCODE = 103;
MySQL Query 8:-

QUES:-
Write SQL query to add a column total price with datatype numeric and
size 10, 2 in a table product.

ANS:-
ALTER TABLE PRODUCT ADD TOTAL PRICE NUMBER (10,2).
MySQL Query 9:-

QUES:-
Sonal needs to display name of teachers, who have “0” as the third character in their
name. She wrote the following query.

SELECT NAME FROM TEACHER WHERE NAME = “$$0?”;

But the query isn’t producing the result. Identify the problem.

ANS:-

The wildcards are incorrect. The corrected query is SELECT NAME FROM
TEACHER WHERE NAME LIKE ‘_ _0%’.
MySQL Query 10:-

QUES:-
Deepika wants to remove all rows from the table BANK. But he needs to
maintain the structure of the table. Which command is used to
implement the same?

ANS:-
DELETE FROM BANK.
MySQL Query 11:-

QUES:-
While creating table ‘customer’, Rahul forgot to add column ‘price’.
Which command is used to add new column in the table. Write the
command to implement the same.

ANS:-
ALTER TABLE CUSTOMER ADD PRICE NUMBER (10, 2).
MySQL Query 12:-

QUES:-
i) To display those company name which are having prize less than 30000.

ii) To display the name of the companies in reverse alphabetical order.

ANS:-
i) SELECT NAME FROM COMPANY WHERE COMPANY. CID=CUSTOMER.
CID AND PRICE < 30000;
ii) SELECT NAME FROM COMPANY ORDER BY NAME DESC;
MySQL Query 13:-

QUES:-
i) To display TEACHERNAME, PERIODS of all teachers whose periods are
more than 25.
ii) To display all the information from the table SCHOOL in descending
order of experience.

ANS:-
i) SELECT TEACHERNAME, PERIODS FROM SCHOOL WHERE
PERIODS>25:
ii) SELECT * FROM SCHOOL;
MySQL Query 14:-

QUES:-
i) TO DISPLAY ALL THE DETAILS OF THOSE WATCHES WHOSE NAME
ENDS WITH ‘TIME’

ii) TO DISPLAY WATCH’S NAME AND PRICE OF THOSE WATCHES


WHICH HAVE PRICE RANGE IN BE-TWEEN 5000-15000.

ANS:-

i) SELECT * FROM WATCHES WHERE WATCH_NAME LIKE ‘%TIME’(Vi


mark for SELECT query) (Vi mark for where clause)

ii) SELECT WATCH_NAME, PRICE WATCH WHERE PRICE BETWEEN 5000


AND 15000;(Vi mark for SELECT query) (Vz mark for where clause)
MySQL Query 13:-

QUES:-
i) To display TEACHERNAME, PERIODS of all teachers whose periods are
more than 25.
ii) To display all the information from the table SCHOOL in descending
order of experience.

ANS:-
i) SELECT TEACHERNAME, PERIODS FROM SCHOOL WHERE
PERIODS>25:
ii) SELECT * FROM SCHOOL;
# Write a program to connect Python with MySQL using
database connectivity and perform the following
operations on data in database: Fetch, Update and
delete the data.

1. CREATE A TABLE

import mysql.connector
demodb = mysql.connector.connect(host="localhost",
user="root",
passwd="computer", database="EDUCATION")
democursor=demodb.cursor( )
democursor.execute("CREATE TABLE STUDENT (admn_no int
primary key,
sname varchar(30), gender char(1), DOB date, stream
varchar(15), marks float(4,2))")
2. INSERT THE DATA

import mysql.connector
demodb = mysql.connector.connect(host="localhost",
user="root",
passwd="computer", database="EDUCATION")
democursor=demodb.cursor( )
democursor.execute("insert into student values (%s, %s,
%s, %s, %s, %s)",
(1245, 'Arush', 'M', '2003-10-04', 'science', 67.34))
demodb.commit( )
3.FETCH THE DATA

import mysql.connector
demodb = mysql.connector.connect(host="localhost",
user="root",
passwd="computer", database="EDUCATION")
democursor=demodb.cursor( )
democursor.execute("select * from student")
for i in democursor:
print(i)
D. UPDATE THE RECORD

import mysql.connector
demodb = mysql.connector.connect(host="localhost",
user="root",
passwd="computer", database="EDUCATION")
democursor=demodb.cursor( )
democursor.execute("update student set marks=55.68
where admn_no=1356")
demodb.commit( )
E. DELETE THE DATA

import mysql.connector
demodb = mysql.connector.connect(host="localhost",
user="root",
passwd="computer", database="EDUCATION")
democursor=demodb.cursor( )
democursor.execute("delete from student where
admn_no=1356")
demodb.commit()

You might also like