Xii - CS - Lab Programs (2022-23)
Xii - CS - Lab Programs (2022-23)
Date:
Aim:
Algorithm:
Step 2: Read the Number from the user and assign it into the identifier num
Step 10: Print the Number is not Palindrome, if res, n are not equal
1
Program Coding:
Output:
Result:
Date:
Aim:
Algorithm:
Step 2: Read the number from the user and pass it to the function.
Step 3: Call the function to check whether the entered number is prime or not.
3
Program Coding:
Output:
Result:
Thus the above program to check whether the given number is prime or not
using function is run and verified successfully.
4
Ex.No.3 Program to generate random number between 1 – 6
to simulate the dice
Date:
Aim:
Algorithm:
Step 1: Start.
Step 2: Repeatedly generate random number using randint(1,6) and display the
number with equal time interval.
Step 5: Stop.
Program Coding:
import random
import time
play='y'
while play=='y':
try:
while True:
for i in range(10):
print()
n = random.randint(1,6)
5
print(n)
time.sleep(0.5)
except KeyboardInterrupt:
if ans.lower()!='y':
play='n'
break
Output:
Your Number is : 3
Result:
6
Ex.No.4 Find the number of upper case and lower case letters in a String
Date:
Aim:
Write a Python program to find the number of upper case and lower case
letters in a string which is passed as an argument to the function.
Algorithm:
Step 4: Find the number of upper case letters and lower case letters using built
in functions
Program Coding:
7
Output:
Result:
Thus the above Python Program to find the number of uppercase, lowercase
characters in a String is run and verified successfully.
8
Ex.No.5 Finding occurrence of any word in a String
Date:
Aim:
Write a Python program to find the occurrence of any word in a string which
is passed as an argument to function.
Algorithm:
Step 4: Call user defined function by passing string and the word as an
argument.
9
Program Coding:
Output:
Result:
Thus the above Python Program to find the occurrence of any word in a
String is run and verified successfully.
10
Ex.No.6 Creating records using Dictionary
Date:
Aim:
Algorithm:
11
Output:
Result:
Thus the above Python Program to create records using Dictionary is run
and verified successfully.
12
Ex.No.7 Menu Driven Program
Date:
Aim:
Algorithm:
Step 2: Display the Menu to the user and read the choice
Step 3: Call the user defined function Area by passing the choice as Parameter
Step 4: Read the side from the user and compute area of square if the choice is 1
Step 6: Read length, breadth from the user and compute area of rectangle if the
choice is 2
Step 8: Read base, height from the user and compute the area of triangle if the
choice is 3
13
Program Coding:
Output:
Result:
Thus the above Python Program to create a menu driven using functions is
run and verified successfully.
14
Ex.No.8 Reading Text File
Date:
Aim:
Write a Python Program to read a text file line by line and display each word
separated by #
Algorithm:
Step 4: Use the string function split() to split the words based on space
Program Coding:
15
Output:
Result:
Thus the above Python program to read a text files line by line and display
each word separated by # is run and verified successfully
16
Ex.No.9 String Functions in Text File
Date:
Aim:
Write a Python Program to read a text file line by line and display the count
of vowels, consonants, uppercase, lowercase and other characters.
Algorithm:
Step 4: Use the string function isupper() to find and print the uppercase count
Step 5: Use the string function islower() to find and print the lowercase count
Step 6: Check each character is in vowels list, increment and print the vowels
Step 7: Use the string function isdigit() to find and print the digit count
vowels_count
Step 9: Print the characters count apart from letters and digits
17
Program Coding:
18
Output:
Result:
Thus the Python Program to read a text file line by line and display the count
of vowels, consonants, and uppercase, lowercase and other characters is run and
verified successfully.
19
Ex.No.10 Creating Binary File
Date:
Aim:
Write a Python program to create binary file and store the details of a
student.
Algorithm:
1. Start.
3. Get student details from the user and store it in dictionary variable.
5. Open the same file in read mode and read its content using load()
7. Stop.
20
Program Coding:
Output:
Result:
Date:
Aim:
Write a Python program to create binary file and update the details of a
student.
Algorithm:
1. Start.
4. Read the file using load() and identify the record to be updated.
5. Update the mark of a student and write the updated record back into the file
using dump().
7. Stop.
22
Program Coding:
Output:
Result:
Thus the above Python Program to create binary file and update the details
of a student is run and verified successfully.
23
Ex.No.12 Creating CSV File
Date:
Aim:
Algorithm:
1. Start.
3. Create writer object and write the product details into the file using
writerow().
4. Open the above created file in read mode using with statement.
7. Stop.
24
Program Coding:
Output:
Result:
Thus the above program to create CSV File is run and verified successfully.
25
Ex.No.13 Menu Driven Program to implement Stack
Date:
Aim:
Algorithm:
Step 8: Call the push function from main to add elements into Stack, if the
user choice is 1
Step 9: Call the pop function to remove an element from Stack, if the user
choice is 2
Step 10: Call the peek function to display the peek element, if the user
choice is 3
Step 11: Call the display function to display the Stack elements, if the user
choice is 4
Step 12: Repeat the Steps from 9 to 11 until the user exits
26
Program Coding:
27
28
Output:
29
Output:
Result:
Date:
Aim:
Algorithm:
Step 3: Setup the connection using the connect() method by passing the
required arguments
Step 6: Execute the query to select all the records from the employee
Step 7: Use fetchall() method to read all the records from the cursor
31
Program Coding:
Output:
Result:
Date:
Aim:
Algorithm:
Step 3: Setup the connection using the connect() method by passing the
required arguments
Step 6: Execute the query to select all the records from the employee
Step 7: Use fetchall() method to read all the records from the cursor
Step 11: Print “Record Not Found”, if the ID is not there in the table
33
Program Coding:
Output:
Result:
Thus the above Program to perform Database Operations is run and verified
successfully.
34
MYSQL – SET 1
Date:
35
4. Add a new attribute HOBBIES into the STUDENT Table
36
MYSQL – SET 2
Date:
37
MYSQL – SET 3
Date:
38
3. Write MYSQL Command to count the records native
wise
4. Display the Average Marks Section wise
39
MYSQL – SET 4
Date:
40
MYSQL – SET 5
Date:
41
2. Equi Join
3. Natural Join
42