[go: up one dir, main page]

0% found this document useful (0 votes)
41 views51 pages

Alpine - Cs - 12

Ffjjs

Uploaded by

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

Alpine - Cs - 12

Ffjjs

Uploaded by

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

S.NO.

AIM
1 Write a program to show entered string is a palindrome or not.

2 Write a program to show statistics of characters in the given line(to counts


the
number of alphabets ,digits, uppercase, lowercase, spaces and other
characters).

3 Write a program to calculate the nth term of Fibonacci series


4 Program to search any word in given string/sentence
5 Creating Menu driven program
6 Input any number from user and check it is Prime no. or not
7
Write a program to show sorting of elements of a list step-by-step, using
bubble sorting technique.

8 Write a Python program for random number generation that generates


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

9 Write a program in Python to read a text file myfile.txt line by line and
display each word separated by a #.

10 Write a Python program to read a text file and display the number of
vowels/consonants/uppercase/lowercase characters in the file
11 Copy all the lines that contain the character `a' in a file and write it to
another r file.

12 Create a binary file with name and roll number, marks. Search for a
given roll number and display the details of student, if not found display
appropriate message.

13 CREATING AND UPDATING RECORDS IN A BINARY FILE

Write a Python program to create a binary file with roll number, name
and marks. Input a roll number and update the marks.

14 Creating a python program to create and search employee’s record in csv file.
Python – SQL connectivity programs
17 Creating a python program to integrate MYSQL with Python (Creating database
and table)
18 Creating a python program to integrate MYSQL with Python (Inserting records
and displaying records)
19 Creating a python program to integrate MYSQL with Python (Searching and
displaying records)
20 Creating a python program to integrate MYSQL with Python (Updating records)
SQL Queries
20. SQL COMMANDS EXERCISE – 1
21. SQL COMMANDS EXERCISE – 2
22. SQL COMMANDS EXERCISE – 3
23. SQL COMMANDS EXERCISE – 4
24. SQL COMMANDS EXERCISE – 5

# AIM 1:WAP to accept a string and whether it is a palindrome or not.

#CODING :

string=input("enter the string")

l=len(string)

p=l-1

index=0

while(index<p):

if(string[index]==string[p]):

index=index+1

p=p-1

else:

print("string is not a palindrome")

break

else:
print("string is palindrome")

OUTPUT:

enter the stringNITIN


string is palindrome
#AIM2 : WAP to counts the number of alphabets ,digits, uppercase, lowercase, # spaces and
other characters(status of a string).

#CODING :

str1 =input("enter a string")

n=c=d=s=u=l=o=0

for ch in str1:

if ch.isalnum():

n+=1

if ch.isupper():

u=u+1

elif ch.islower():

l=l+1

elif ch.isalpha():

c=c+1

elif ch.isdigit():

d=d+1

elif ch.isspace():
s=s+1

else:

o=o+1

print("no.of alpha and digit",n)

print("no.of capital alpha",u)

print("no.of smallalphabet",l)

print("no.of digit",d)

print("no. of spaces",s)

print("no of other character",o)

OUTPUT:

enter a stringWELcome to My LAb01#


no.of alpha and digit 16
no.of capital alpha 6
no.of smallalphabet 8
no.of digit 2
no. of spaces 3
no of other character 1
#AIM 3: : Write a program to calculate the nth term of Fibonacci series

#Program to find 'n'th term of fibonacci series


#Fibonacci series :
0,1,1,2,3,5,8,13,21,34,55,89,...
#nth term will be counted from 1 not 0

#CODING :
def nthfiboterm(n):
if n<=1:
return n
else:
return (nthfiboterm(n-1)+nthfiboterm(n-2))

num = int(input("Enter the 'n' term to find in fibonacci :"))


term =nthfiboterm(num)
print(num,"th term of fibonacci series is :",term)

OUTPUT:
Enter the 'n' term to find in fibonacci
:10 10 th term of fibonacci series is :
55
Program4 : Program to search any word in given string/sentence

#Program to find the occurence of any word in a string def


countWord(str1,word):
s = str1.split()
count=0
for w in s:
if w==word:
count+=1
return count

str1 = input("Enter any sentence :")


word = input("Enter word to search in sentence :") count =
countWord(str1,word)
if count==0:
print("## Sorry! ",word," not present ")
else:
print("## ",word," occurs ",count," times ## ")

OUTPUT

Enter any sentence :my computer your computer our computer everyones computer
Enter word to search in sentence :computer
## computer occurs 4 times ##

Enter any sentence :learning python is fun


Enter word to search in sentence :java
## Sorry! java not present

Page :
5:To write a menu driven Python Program to find Area of Circle, Rectangle and Triangle. Using
function.

def Circle(r):
Area=3.141*(r**2)
print("The Area of circle is:",Area)

def Rectangle(L,B):
R=L*B
print("The Area of rectangle is:",R)

def Triangle(B,H):
R=0.5*B*H
print("The Area of triangle is:",R)
print("1.Area of Circle")
print("2.Area of Rectangle")

print("3.Area of Triangle") ch=int(input("Enter your


choice")) if ch==1:
a=float(input("enter the radius value")) Circle(a)
elif ch==2:
L=int(input("Enter the Length of the Rectangle")) B=int(input("Enter the
Breadth of the Rectangle")) Rectangle(L,B)
elif ch==3:
B=int(input("Enter the Base of Triangle:"))
H=int(input("Enter the Height of Triangle:"))
Triangle(B,H)
else:
print("Invalid option")
OUTPUT:

Page :
1. Area of Circle
2. Area of Rectangle
3. Area of Triangle Enter
your choice1
Enter the radius value 5
The Area of circle is: 78.525
1.Area of Circle
2. Area of Rectangle
3. Area of Triangle

Enter your choice 2


Enter the Length of the Rectangle 7 Enter
the Breadth of the Rectangle 5 The
Area of rectangle is: 35

Page :
Program 6: Input any number from user and check it is Prime no. or not

OUTPUT

Page :
AIM 7: Write a AIM to show sorting of elements of a list step-by-step, using bubble sorting
technique.

#CODING :

OUTPUT:

Page :
Aim:8
To write a Python program for random number generation that generates
random
numbers between 1 to 6 (simulates a dice).
Program:

Output:
Enter any number:
2 Too low
Enter number
again: 4 Too high!
Enter number
again: 3 you guessed it
right!!

Page :

9. Write a program in Python to read a text file myfile.txt line by line and
display each word separated by a #. If myfile.txt contains

For every action there is equal and opposite


reaction.

Energy can neither be created nor be destroyed.

AIM:
To read a text file myfile.txt line by line and display each word separated by a #.

PROGRAM:

file1=open('myfile2.txt','r')
for line in file1:
word=line.split() for i
in word:
print(i,end='# ')
file1.close()

OUTPUT:

For#every#action#there#is#equal#and#opposite#reaction.#Energy#can#neither#be#c
reat ed#no r#be#destroyed.#

Aim:10 Page :

To write Python program to read a text file and display the number of vowels/
consonants/ uppercase/ lowercase characters in the file.

Program:

AI.txt
As computer can understand only machine language, a Translator is
needed to convert a program written in assembly or hign=level language
to machine Languang to Machine Language

Output:
Page :
('Vowels are :', 58)
('Consonants :', 90)
('Lower_case_letters :', 143)
('Upper_case_letters :', 5)

11. Copy all the lines that contain the character `a' in a file and write it to
another file.
AIM:
To Copy all the lines that contain the character `a' in a file and write it
to another file

PROGRAM:

12. Create a binary file with name and roll number, marks. Search for a
given roll number and display the details of student, if not found display
appropriate message.

Page :
Page :
Output
OUTPUT:
Enter roll
number:1001 Enter
name:Lakshmi Enter
English mark:88
Enter Maths
mark:76 Enter CS
mark:93
Do u want to append more
records?(y/n)...?y Enter roll
number:1002
Enter name:Rani
Enter English
mark:90 Enter
Maths mark:85
Enter CS mark:86
Do u want to append more
records?(y/n)...?y Enter roll
number:1003
Enter name:Vishnu
Enter English
mark:67 Enter
Maths mark:78
Enter CS mark:89
Do u want to append more
records?(y/n)...?y Enter roll number:1004
Enter name:Rishi
Enter English
mark:92 Enter
Maths mark:67
Enter CS mark:84
Do u want to append more
records?(y/n)...?y Enter roll
number:1005
Enter name:Seetha Enter English
mark:86 Enter Maths mark:59 Page :
Enter CS mark:70
Do u want to append more records?(y/n)...?n

Page :
Students Details
{'Rollno': 1001, 'Name': 'Lakshmi', 'Mark1': 88, 'Mark2': 76, 'Mark3': 93}
{'Rollno': 1002, 'Name': 'Rani', 'Mark1': 90, 'Mark2': 85, 'Mark3': 86}
{'Rollno': 1003, 'Name': 'Vishnu', 'Mark1': 67, 'Mark2': 78, 'Mark3': 89}
{'Rollno': 1004, 'Name': 'Rishi', 'Mark1': 92, 'Mark2': 67, 'Mark3': 84}
{'Rollno': 1005, 'Name': 'Seetha', 'Mark1': 86, 'Mark2': 59, 'Mark3': 70}

Students Details(output ****)


{'Rollno': 1003, 'Name': 'Vishnu', 'Mark1': 67, 'Mark2': 78, 'Mark3': 89}
Record found

13. CREATING AND UPDATING RECORDS IN A BINARY FILE

Write a Python program to create a binary file with roll number, name and marks.
Input a roll number and update the marks.

Page :
OUTPUT:
Enter roll number:101 Enter
name:Priya Enter English
mark:67 Enter Maths
mark:78 Enter CS mark:89
Do u want to append more records?(y/n)...?y
Enter roll number:102
Enter name:Yavanesh Enter
English mark:88 Enter Maths
mark:90 Enter CS mark:96
Do u want to append more records?(y/n)...?y
Enter roll number:103
Page :
Enter name:Vinoth Enter
English mark:45 Enter
Maths mark:90 Enter CS
mark:97
Do u want to append more records?(y/n)...?y
Enter roll number:104
Enter name:Harshi Enter
English mark:73 Enter Maths
mark:56 Enter CS mark:90
Do u want to append more records?(y/n)...?y
Enter roll number:105
Enter name:Chanu
Enter English mark:66
Enter Maths mark:79 Enter
CS mark:91
Do u want to append more records?(y/n)...?n

Students Details
{'Rollno': 101, 'Name': 'Priya', 'Mark1': 67, 'Mark2': 78, 'Mark3': 89}
{'Rollno': 102, 'Name': 'Yavanesh', 'Mark1': 88, 'Mark2': 90, 'Mark3': 96}
{'Rollno': 103, 'Name': 'Vinoth', 'Mark1': 45, 'Mark2': 90, 'Mark3': 97}
{'Rollno': 104, 'Name': 'Harshi', 'Mark1': 73, 'Mark2': 56, 'Mark3': 90}
{'Rollno': 105, 'Name': 'Chanu', 'Mark1': 66, 'Mark2': 79, 'Mark3': 91}

Student Details
Enter roll number:102
{'Rollno': 102, 'Name': 'Yavanesh', 'Mark1': 93, 'Mark2': 90, 'Mark3': 96}
Record updated

Page :
14.
CREATING A PYTHON PROGRAM TO CREATE AND SEARCH EMPLOYEE’S RECORD
IN CSV FILE.

AIM:

To write a Python program Create a CSV file to store Empno, Name, Salary
and search any Empno and display Name, Salary and if not found display
appropriate message.

SOURCE CODE:

Result:

Thus, the above Python program has been executed and the
output is verified successfully.

Page :
SAMPLE OUTPUT:
PYTHON PROGRAM EXECUTED OUTPUT:

**************************************************************************
****

Page :
:EX.NO: 15

CREATING A PYTHON PROGRAM TO IMPLEMENT STACK OPERATIONS(LIST)

To write a Python program to implement Stack using a list data-structure,

to perform the following operations:

(i) To Push an object containing Doc_ID and Doc_name of doctors who specialize in "ENT"
to the stack.
(ii) (ii) To Pop the objects from the stack and display them.
(iii)
(iv) (iii) To display the elements of the stack (after performing PUSH or POP)

SOURCE CODE:

Page :
Result:

Thus, the above Python program has been executed and the
output is verified successfully.
SAMPLE OUTPUT:
Python Program Executed Output:

Page :
EX.NO: 16

CREATING A PYTHON PROGRAM TO IMPLEMENT STACK OPERATIONS(Dictionary)

AIM:
To Write a program, with separate user-defined functions to perform
the following
operations:
(i) To Create a function Push(Stk,D) Where Stack is an empty list and D is Dictionary of Items. from
this Dictionary Push the keys (name of the student) into a stack, where the
corresponding value (marks) is greater than 70.
(ii) To Create a Function Pop(Stk) , where Stk is a Stack implemented by a list of student
names. The function returns the items deleted from the stack.
(iii) To display the elements of the stack (after performing PUSH or POP).
Source Code:

Page :
Page :
Result:

Thus, the above Python program has been executed and the
output is verified successfully.

Sample Output:

Page :
EX.NO:
17
CREATING A PYTHON PROGRAM TO INTEGRATE MYSQL WITH
PYTHON (CREATING DATABASE AND TABLE)
AIM:
To write a Python Program to integrate MYSQL with Python to create
Database and Table to store the details of employees.

Source Code:

Result:

Thus, the above Python program has been executed and the
output is verified successfully.

Page :
Sample Output:

*****************************************************************************
**************************

Page :
EX.NO:
18
CREATING A PYTHON PROGRAM TO INTEGRATE MYSQL WITH
PYTHON
(INSERTING RECORDS AND DISPLAYING RECORDS)
AIM
:
To write a Python Program to integrate MYSQL with Python by
inserting records to Emp table and display the records.

SOURCE CODE:

Result:

Thus, the above Python program has been executed and the
output is verified successfully.

Page :
Page :
SAMPLE OUTPUT:

Python Executed Program Output:

**************************************************************************************************************************************************************************
****

Page :
EX.NO:
19
CREATING A PYTHON PROGRAM TO INTEGRATE MYSQL WITH PYTHON
(SEARCHING AND DISPLAYING RECORDS)

AIM:
To write a Python Program to integrate MYSQL with Python to
search an Employee using EMPID and display the record if present
in already existing table EMP, if not display the appropriate
message.

SOURCE CODE:

Result:

Thus, the above Python program has been executed and the
output is verified successfully.

SAMPLE OUTPUT:

Python Executed Program Output:

Page :
Page :
EX.NO: 20
DATE:
CREATING A PYTHON PROGRAM TO INTEGRATE MYSQL WITH
PYTHON (UPDATING RECORDS)

AIM:
To write a Python Program to integrate MYSQL with Python to
search an Employee using EMPID and update the Salary of an
employee if present in already existing table EMP, if not display
the appropriate message.
SOURCE CODE:

Result:

Thus, the above Python program has been executed and the
output is verified successfully.

Page :
Page :
SAMPLE OUTPUT:

Python Executed Program Output:

******************************************************************************************************************************************
********

Page :
SQL COMMANDS EXERCISE
- 1
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 COMPUTE 1997-01-10 120
R
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 COMPUTE 1997-02-25 210
R
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;

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

SHOW TABLES;
Output:

Page :
SQL COMMANDS EXERCISE - 2
Ex.No: 22
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 COMPUTE 1997-01-10 120
R
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 COMPUTE 1997-02-25 210
R
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:

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

SELECT ROLLNO,NAME,DEPT FROM STU;

Output:

(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:

********************************************************************************************

Page :
Ex.No: 23 SQL COMMANDS EXERCISE

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

Rollno Name Gender Age Dept DOA Fees


1 Arun M 24 COMPUTE 1997-01-10 120
R
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 COMPUTE 1997-02-25 210
R
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:

Page :
(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:

*******************************************************************************
***************************

Page :
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 COMPUTE 1997-01-10 120
R
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 COMPUTE 1997-02-25 210
R
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):

Page :
Page :
(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:
*******************************************************************************************

Page :
Ex.No: 24 SQL COMMANDS EXERCISE
- 5 DATE:

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

Ucode Uname Ucolor StockDate


1 Shirt White 2021-03-31
2 Pant Black 2020-01-01
3 Skirt Grey 2021-02-18
4 Tie Blue 2019-01-01
5 Socks Blue 2019-03-19
6 Belt Black 2017-12-09

TABLE: COST

Ucode Size Price Company


1 M 500 Raymond
1 L 580 Mattex
2 XL 620 Mattex
2 M 810 Yasin
2 L 940 Raymond
3 M 770 Yasin
3 L 830 Galin
4 S 150 Mattex

(a) To Display the average price of all the Uniform of Raymond Company from table COST.

SELECT AVG(PRICE) FROM COST WHERE COMPANY='RAYMOND';

Output:

(b) To display details of all the Uniform in the Uniform table in descending order of Stock date.

SELECT * FROM UNIFORM ORDER BY STOCKDATE DESC;

Output:

Page :
(c) To Display max price and min price of each company.

SELECT COMPANY,MAX(PRICE),MIN(PRICE) FROM COST GROUP BY COMPANY;

Output:

(d) To display the company where the number of uniforms size is more than 2.

SELECT COMPANY, COUNT(*) FROM COST GROUP BY COMPANY HAVING


COUNT(*)>2;

Output:

(e) To display the Ucode, Uname, Ucolor, Size and Company of tables uniform and cost.

SELECT U.UCODE,UNAME,UCOLOR,SIZE,COMPANY FROM UNIFORM U,COST C


WHERE U.UCODE=C.UCODE;

Output:

*********************************************************************
********************

Page :
Page :

You might also like