Alpine - Cs - 12
Alpine - Cs - 12
AIM
1 Write a program to show entered string is a palindrome or not.
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.
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
#CODING :
l=len(string)
p=l-1
index=0
while(index<p):
if(string[index]==string[p]):
index=index+1
p=p-1
else:
break
else:
print("string is palindrome")
OUTPUT:
#CODING :
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 smallalphabet",l)
print("no.of digit",d)
print("no. of spaces",s)
OUTPUT:
#CODING :
def nthfiboterm(n):
if n<=1:
return n
else:
return (nthfiboterm(n-1)+nthfiboterm(n-2))
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
OUTPUT
Enter any sentence :my computer your computer our computer everyones computer
Enter word to search in sentence :computer
## computer occurs 4 times ##
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")
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
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
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}
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
(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
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:
**************************************************************************************************************************************************************************
****
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:
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:
******************************************************************************************************************************************
********
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
USE STUDENTS;
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:
(a) Write a Query to insert all the rows of above table into Info table.
(b) Write a Query to display all the details of the Employees from the above table 'STU'.
Output:
Page :
(c) Write a query to Rollno, Name and Department of the students from STU table.
Output:
Output:
Output:
********************************************************************************************
Page :
Ex.No: 23 SQL COMMANDS EXERCISE
AIM:
To write Queries for the following Questions based on the given table:
Output:
(b) Write a Query to list name of the students whose ages are between 18 to 20.
Output:
Page :
(c) Write a Query to display the name of the students whose name is starting with 'A'.
Output:
(d) Write a query to list the names of those students whose name have second alphabet 'n' in their
names.
Output:
*******************************************************************************
***************************
Page :
Ex.No: 23 SQL COMMANDS EXERCISE - 4
DATE:
AIM:
To write Queries for the following Questions based on the given table:
(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.
Output(After Update):
Page :
Page :
(c) Write a Query to add a new column Area of type varchar in table STU.
Output:
(d) Write a Query to Display Name of all students whose Area Contains NULL.
Output:
(e) Write a Query to delete Area Column from the table STU.
Output:
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
TABLE: COST
(a) To Display the average price of all the Uniform of Raymond Company from table COST.
Output:
(b) To display details of all the Uniform in the Uniform table in descending order of Stock date.
Output:
Page :
(c) To Display max price and min price of each company.
Output:
(d) To display the company where the number of uniforms size is more than 2.
Output:
(e) To display the Ucode, Uname, Ucolor, Size and Company of tables uniform and cost.
Output:
*********************************************************************
********************
Page :
Page :