Practical File 2023-24
Practical File 2023-24
OUTPUT
Enter any number :6
Factorial of 6 is : 720
Program 2: Input any number from user and check it is Prime no. or Composite
OUTPUT
Enter any number :117
## Number is composite ##
>>>
Enter any number :119
## Number is composite ##
>>>
Enter any number :113
## Number is Prime ##
>>>
Page :
Enter any number :7
## Number is Prime ##
>>>
Enter any number :19
## Number is Prime ##
SOURCE CODE:
Page :
SAMPLE OUTPUT:
Page :
Program 5: Program to search any word in given string/sentence using a
function with two arguments- the string and the word to search.
#Program to find the occurrence 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
OUTPUT
Enter any sentence :my computer your computer our computer everyones
computer Enter word to search in sentence :computer
## computer occurs 4 times ##
Page :
Enter any sentence :learning python is
fun Enter word to search in sentence
:java
## Sorry! java not present
Program 6: To write a menu driven Python Program to find Factorial and sum of
list of numbers using function.
Page :
Python Executed Program Output:
Output
Page :
Program 8 :
To write a Python program to generate random number between 1 to 6 to simulate
the roll of a dice.
Output
Program 9 : Program to read and display file content line by line with each word
separated by ‘#’.
f = open("mytext.txt")
for line in f:
words = line.split()
for w in words:
print(w+'#',end='')
print()
f.close()
Page :
NOTE : if the original content of file is:
India is my
country I love
python
Python learning is fun
OUTPUT
India#is#my#country#
I#love#python#
Python#learning#is#fun
#
Program 10: Program to read the content of file and display the total number of
consonants, uppercase, vowels and lower case characters.
f = open("mytext.txt")
v=c=u=l=o=0
data = f.read()
vowels=['a','e','i','o','u'] # vowels= ‘aeiou’
for ch in data:
if ch.isalpha():
if ch.lower() in vowels:
v+=1
else:
c+=1
if ch.isupper():
u+=1
elif ch.islower():
l+=1
else:
o+=1
print("Total Vowels in file:",v)
print("Total Consonants in file :",c)
print("Total Capital letters in file:",u)
print("Total Small letters in file:",l)
print("Total Other than letters :",o)
f.close()
NOTE : if the original content of file is:
India is my country
I love python
Python learning is fun 123@
Output
Total Vowels in file: 16
Total Consonants in file : 30
Total Capital letters in file: 3
Total Small letters in file: 43
Page :
Total Other than letters : 16
Program 11: Program to create binary file to store Rollno and Name, Search any
Rollno and display name if Rollno found otherwise “Rollno not found”
Page :
Program 12: To write a python program to read lines from a text file "Sample.txt" and copy those lines
into another file which are starting with an alphabet 'a' or 'A'.
Page :
Program 13: To write a Python Program to Create a binary file with roll number, name, mark and
update/modify the mark for a given roll number.
Page :
Output:
Page :
Program 14: To write a Python Program to Create a binary file with roll number, name, mark and
update/modify the mark for a given roll number.
Page :
OUTPUT
Program 15:
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.
Output:
Page :
Program 16:
To write a Python program to implement Stack using a list data-structure.
Page :
SOURCE CODE:
OUTPUT:
Page :
Page :
Program 17:
To write a Python Program to integrate MYSQL with Python by inserting records to Emp table and display
the records.
Page :
Page :
OUTPUT
MySQL OUTPUT
Program 18:
To write a Python Program to integrate MYSQL with Python to search an Employee
Page :
using EMPID and display the record if present in already existing table EMP, if not
display the appropriate message.
OUTPUT
Page :
Program 19:
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.
Output:
Page :
Program 20:
SQL COMMANDS EXERCISE – 1
Table Name : STU
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
Page :
(e) Write a Query to List all the tables that exists in the current database.
Sol:
mysql> SHOW TABLES;
Output:
(f) Write a Query to insert all the rows of above table into STU 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);
(g) Write a Query to display all the details of the Employees from the above table 'STU'.
Output:
(h) Write a query to Rollno, Name and Department of the students from STU table.
mysql> SELECT ROLLNO,NAME,DEPT FROM STU;
Page :
Program 21:
SQL COMMANDS EXERCISE –
2
To write Queries for the following Questions based on the given table:
Output:
Output:
Output:
Page :
(d) Write a Query to list name of the students whose ages are between 18 to 20.
Sol:
mysql> SELECT NAME FROM STU WHERE AGE BETWEEN 18 AND 20;
Output:
(e) Write a Query to display the name of the students whose name is starting with 'A'.
Sol:
Output:
(f) Write a query to list the names of those students whose name have second alphabet
'n' in their names.
Sol:
Page 26 of 26