0% found this document useful (0 votes)
8 views12 pages

CS - Prefinal Lab

Uploaded by

Vanitha R
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)
8 views12 pages

CS - Prefinal Lab

Uploaded by

Vanitha R
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/ 12

CS PRE-FINAL LAB PROGRAMS

PART-A-PYTHON PROGRAMS
1. PROGRAM -1: Write the program to find the given string is
palindrome or not.

AIM:
To write the program to find the given string is palindrome or
not.
PROGRAM:

print("Palindrome checking program")


ans='y'
while ans=='y':
s=input("Enter the string :")
s1=s[::-1]
if s==s1:
print("The given string",s,"is a palindrome")
else:
print("The given string ",s,"is not a palindrome")
ans=input("Do you want to add check for another string(y/n):")

OUTPUT1:
Palindrome checking program
Enter the string : madam
The given string madam is a palindrome
Do you want to add check for another string(y/n):y
Enter the string : eleven
The given string eleven is a palindrome
Do you want to add check for another string(y/n):n
>>>

RESULT:
Thus the above program has been executed successfully and the
output is verified.
3

2. PROGRAM -2 : Write a random number generator that generates


random numbers between 1 and 6 (simulates a dice).

AIM:
To write a random number generator that generates random
numbers between 1 and 6 (simulates a dice).

PROGRAM:

import random
print("Dice game ")
print("Game starts...")
ans='y'
while ans=='y':
print("Dice rolling ... ")
s=random.randint(1,6)
print("You got:",s)
ans=input("Do you want to roll again the dice (y/n):")
print("See you again.. Bye .. ")

OUTPUT:

Dice game
Game starts...
Dice rolling....
You got: 5
Do you want to roll again the dice (y/n):y
Dice rolling....
You got: 2
Do you want to roll again the dice (y/n):y
Dice rolling....
You got: 2
Do you want to roll again the dice (y/n):y
Dice rolling....
You got: 6
Do you want to roll again the dice (y/n):n
See you again.. Bye…

RESULT:
Thus the above program has been executed successfully and the
output is verified
4

3. PROGRAM-3 :Read a text file and display the number of


vowels/consonants/uppercase/lowercase characters in the file.

AIM:
To read a text file and display the number of
vowels/consonants/uppercase/lowercase characters in the file.

PROGRAM:

a=open('sample.txt','r')
b=a.read()
v=c=uc=lc=0
for i in b:
if i.isalpha():
if i in ‘AEIOUaeiou’:
v+=1
else:
c+=1
if i.isupper():
uc+=1
elif i.islower():
lc+=1
print("The number of vowels in the file is :",v)
print("The number of consonants in the file is :",c)
print("The number of upper case letters in the file is :",uc)
print("The number of lower case letters in the file is :",lc)
a.close()

FILE CONTENT :

I am a computer science student.


I am learning python programming.

OUTPUT:
The number of vowels in the file is : 20
The number of consonants in the file is : 46
The number of upper case letters in the file is : 2
The number of lower case letters in the file is : 52

RESULT:
Thus the above program has been executed successfully and the
output is verified.
5

4. PROGRAM-4:Read a text file and count the number of occurrence of


the particular word in the file content.

AIM:
To read a text file and count the number of occurrence of the
particular word in the file content.

PROGRAM:

a=open("sample.txt",'r')
b=a.read()
c=b.split()
d=0
w=input("Enter the word which you want to count:")
for i in c:
if i.lower()==w:
d+=1
if d==0:
print("The given word",w,"not found in the file content")
else:
print("The given word",w,"found",d,"time(s) in the file
content")

OUTPUT:

Enter the word which you want to count:python


The given word python found 2 time(s) in the file content

Enter the word which you want to count:game


The given word game not found in the file content

RESULT:
Thus the above program has been executed successfully and the
output is verified
SQL COMMANDS EXERCISE - 1
Ex.No: 20
DATE:

AIM:
To write Queries for the following Questions based on the given table:

Rollno Name Gender Age Dept DOA Fees


1 Arun M 24 COMPUTER 1997-01-10 120
2 Ankit M 21 HISTORY 1998-03-24 200
3 Anu F 20 HINDI 1996-12-12 300
4 Bala M 19 NULL 1999-07-01 400
5 Charan M 18 HINDI 1997-09-05 250
6 Deepa F 19 HISTORY 1997-06-27 300
7 Dinesh M 22 COMPUTER 1997-02-25 210
8 Usha F 23 NULL 1997-07-31 200

(a) Write a Query to Create a new database in the name of "STUDENTS".

CREATE DATABASE STUDENTS;

(b) Write a Query to Open the database "STUDENTS".

USE STUDENTS;

(c) Write a Query to create the above table called: "STU"

CREATE TABLE STU(ROLLNO INT PRIMARY KEY,NAME VARCHAR(10),


GENDER VARCHAR(3), AGE INT,DEPT VARCHAR(15),
DOA DATE,FEES INT);

(d) Write a Query to list all the existing database names.

SHOW DATABASES;

(e) Write a Query to List all the tables that exists in the current database.

SHOW TABLES;
Output:
SQL COMMANDS EXERCISE - 2
Ex.No: 21
DATE:

AIM:
To write Queries for the following Questions based on the given table:

Rollno Name Gender Age Dept DOA Fees


1 Arun M 24 COMPUTER 1997-01-10 120
2 Ankit M 21 HISTORY 1998-03-24 200
3 Anu F 20 HINDI 1996-12-12 300
4 Bala M 19 NULL 1999-07-01 400
5 Charan M 18 HINDI 1997-09-05 250
6 Deepa F 19 HISTORY 1997-06-27 300
7 Dinesh M 22 COMPUTER 1997-02-25 210
8 Usha F 23 NULL 1997-07-31 200

(a) Write a Query to insert all the rows of above table into Info table.

INSERT INTO STU VALUES (1,'Arun','M', 24,'COMPUTER','1997-01-10', 120);

INSERT INTO STU VALUES (2,'Ankit','M', 21,'HISTORY','1998-03-24', 200);

INSERT INTO STU VALUES (3,'Anu','F', 20,'HINDI','1996-12-12', 300);

INSERT INTO STU VALUES (4,'Bala','M', 19, NULL,'1999-07-01', 400);

INSERT INTO STU VALUES (5,'Charan','M', 18,'HINDI','1997-06-27', 250);

INSERT INTO STU VALUES (6,'Deepa','F', 19,'HISTORY','1997-06-27', 300);

INSERT INTO STU VALUES (7,'Dinesh','M', 22,'COMPUTER','1997-02-25', 210);

INSERT INTO STU VALUES (8,'Usha','F', 23, NULL,'1997-07-31', 200);

(b) Write a Query to display all the details of the Employees from the above table 'STU'.

SELECT * FROM STU;

Output:
(c) Write a query to Rollno, Name and Department of the students from STU table.

SELECT ROLLNO,NAME,DEPT FROM STU;

(d) Write a Query to select distinct Department from STU table.

SELECT DISTICT(DEPT) FROM STU;

Output:

(e) To show all information about students of History department.

SELECT * FROM STU WHERE DEPT='HISTORY';

Output:

********************************************************************************************
Ex.No: 22 SQL COMMANDS EXERCISE - 3

DATE:

AIM:
To write Queries for the following Questions based on the given table:

Rollno Name Gender Age Dept DOA Fees


1 Arun M 24 COMPUTER 1997-01-10 120
2 Ankit M 21 HISTORY 1998-03-24 200
3 Anu F 20 HINDI 1996-12-12 300
4 Bala M 19 NULL 1999-07-01 400
5 Charan M 18 HINDI 1997-09-05 250
6 Deepa F 19 HISTORY 1997-06-27 300
7 Dinesh M 22 COMPUTER 1997-02-25 210
8 Usha F 23 NULL 1997-07-31 200

(a) Write a Query to list name of female students in Hindi Department.

SELECT NAME FROM STU WHERE DEPT='HINDI' AND GENDER='F';

Output:

(b) Write a Query to list name of the students whose ages are between 18 to 20.

SELECT NAME FROM STU WHERE AGE BETWEEN 18 AND 20;

Output:
(c) Write a Query to display the name of the students whose name is starting with 'A'.

SELECT NAME FROM STU WHERE NAME LIKE 'A%';

Output:

(d) Write a query to list the names of those students whose name have second alphabet 'n' in their
names.

SELECT NAME FROM STU WHERE NAME LIKE '_N%';

Output:

**********************************************************************************************************
Ex.No: 23 SQL COMMANDS EXERCISE - 4

DATE:

AIM:
To write Queries for the following Questions based on the given table:

Rollno Name Gender Age Dept DOA Fees


1 Arun M 24 COMPUTER 1997-01-10 120
2 Ankit M 21 HISTORY 1998-03-24 200
3 Anu F 20 HINDI 1996-12-12 300
4 Bala M 19 NULL 1999-07-01 400
5 Charan M 18 HINDI 1997-09-05 250
6 Deepa F 19 HISTORY 1997-06-27 300
7 Dinesh M 22 COMPUTER 1997-02-25 210
8 Usha F 23 NULL 1997-07-31 200

(a) Write a Query to delete the details of Roll number is 8.

DELETE FROM STU WHERE ROLLNO=8;

Output (After Deletion):

(b) Write a Query to change the fess of Student to 170 whose Roll number is 1, if the existing fess
is less than 130.

UPDATE STU SET FEES=170 WHERE ROLLNO=1 AND FEES<130;

Output(After Update):
(c) Write a Query to add a new column Area of type varchar in table STU.

ALTER TABLE STU ADD AREA VARCHAR(20);

Output:

(d) Write a Query to Display Name of all students whose Area Contains NULL.

SELECT NAME FROM STU WHERE AREA IS NULL;

Output:

(e) Write a Query to delete Area Column from the table STU.

ALTER TABLE STU DROP AREA;

Output:

(f) Write a Query to delete table from Database.

DROP TABLE STU;

Output:
*******************************************************************************************

You might also like