Cs Practical Revised
Cs Practical Revised
Kshitij Choudhary
XII-C
Program:-1
Source Code:-
Output
Program:- 2
Source Code:-
Output
Program 3:-
Source Code:-
Output
Program 3:-
Source Code:-
Output
Program 4:-
Source Code:-
Output
Program 5:-
Source Code:-
Output
Program 6:-
Source Code:-
Output
Program 7:-
Source Code:-
Output
Program 8:-
Source Code:-
Output
Program 9:-
Source Code:-
Output
Program 10:-
Source Code:-
Output
Program 11:-
Source Code:-
Output
Program 12:-
12
123:-
Source Code:-
Output
Program 13:-
333
22
1
Source Code:-
Output
Program 14:-
Source Code:-
Output
Program 15:-
Source Code:-
Output
Program 16:-
Source Code:-
Output
Program 17:
Source Code:-
Output
Program 18:
Source Code:-
Output
Program 19:
Source Code:-
Output
Program 20:-
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:-
Source Code:-
Output
Program 22:-
Source Code:-
Output
Program 23:-
Source Code:-
Output
Program 24:-
Source Code:-
Output
Program 25:-
Source Code:-
Output
MySQL Query 1:-
ANS:-
i) SELECT * FROM CLIENT WHERE City="Delhi";
ANS:-
i. SELECT * FROM Model ORDER BY
DateOfManufacture;
ANS:-
i. SELECT MAX(Interest) FROM LOANS;
QUES:-
ii) To display the CNAME of all customers from the table TRAVEL who are
travelling by vechicle with code Vo1 or Vo2.
ANS:-
QUES:-
ii) To display the NAME of the drivers from the table TRIP who are
traveling by transport vehicle with code 101 or 103.
ANS:-
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.
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.
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’
ANS:-
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()