google.com, pub-6167773875660516, DIRECT, f08c47fec0942fa0 2nd puc computer science lab manual | class 12 computer science lab programs - 2nd puc computer science

2nd puc computer science lab manual | class 12 computer science lab programs

 2nd puc computer science lab manual,2nd puc computer science lab programs pdf 2025,2nd puc computer science lab manual 2025 pdf free download,2nd puc computer science lab manual python,2nd puc computer science lab manual 2025 python,2nd puc computer science lab manual 2025-26,2nd puc computer science lab manual karnataka,2nd puc computer science lab manual pdf download,class 12 computer science lab manual,class 12 computer science lab programs,class 12th computer science lab manual,cbse class 12 computer science lab manual,ncert lab manual class 12 computer science, computer science lab manual class 12 pdf free download,class 12 computer science lab,class 12 computer science practical book solutions,class 12 computer science practical program,

2nd puc computer science lab programs


1. Write a python program using a function to print n Fibonacci numbers.


def fibo(n):

    first = 0

    second = 1

    for i in range(n):

        print(first, end=' ')

        third = first + second

        first = second

        second = third

n = int(input("How many Fibonacci numbers do you want to print? "))

print("Fibonacci sequence:")

fibo(n)

2. Write a menu driven program in python to find factorial and sum of natural of n Numbers using function.

def find_factorial(n):

    factorial = 1

    for i in range(1, n + 1):

        factorial *= i

    return factorial


def sum_natural_numbers(n):

    sum = 0

    for i in range(1, n + 1):

        sum += i

    return sum


while True:

    print("\n--- MENU ---")

    print("1. Find Factorial of a number")

    print("2. Find Sum of n Natural Numbers")

    print("3. Exit")


    choice = int(input("Enter your choice (1-3): "))


    if choice == 1:

        num = int(input("Enter a number to find factorial: "))

        if num < 0:

            print("Factorial is not defined for negative numbers.")

        else:

            result = find_factorial(num)

            print("Factorial of ",num," is ",result)


    elif choice == 2:

        num = int(input("Enter a number to find sum of natural numbers: "))

        if num < 1:

            print("Please enter a number greater than 0.")

        else:

            result = sum_natural_numbers(num)

            print("Sum of first ",num," natural numbers is ",result)


    elif choice == 3:

        print("Thanks for using the program. Goodbye!")

        break


    else:

        print("Invalid choice! Please enter 1, 2 or 3.")

3. Write a python program using user defined function to calculate interest amount using simple interest method and compound interest method and find the difference of interest amount between the two methods.

def calculate_simple_interest(principal, rate, time):

    si = (principal * rate * time) / 100

    return si


def calculate_compound_interest(principal, rate, time):

    amount = principal * (1 + rate / 100) ** time

    ci = amount - principal

    return ci


print("Welcome to the Interest Calculator!")


p = float(input("Enter the principal amount (₹): "))

r = float(input("Enter the annual interest rate (%): "))

t = int(input("Enter the time in years: "))


simple_interest = calculate_simple_interest(p, r, t)

compound_interest = calculate_compound_interest(p, r, t)


difference = compound_interest - simple_interest


print("\nResults:")

print("Simple Interest = ₹%.2f" %simple_interest)

print("Compound Interest = ₹%.2f" %compound_interest)

print("Difference = ₹%.2f" %difference)

4. Write a Python Program to create a text file and to read a text file and display the number of vowels, consonants, uppercase and lowercase characters in the file.


with open("sample.txt", "w") as file:

     sentence=input("Enter the sentence:")

    file.write(sentence)


vowels_list = "aeiouAEIOU"


vowels = 0

consonants = 0

uppercase = 0

lowercase = 0


with open("sample.txt", "r") as file:

    text = file.read()


    for char in text:

        if char.isalpha():  

            if char in vowels_list:

                vowels += 1

            else:

                consonants += 1


            if char.isupper():

                uppercase += 1

            elif char.islower():

                lowercase += 1


print("Number of vowels:", vowels)

print("Number of consonants:", consonants)

print("Number of uppercase letters:", uppercase)

print("Number of lowercase letters:", lowercase)


5.Write a python code to find the number of lines, number of words and number of characters in a text file.


filename = input("Enter the file name (with .txt extension): ")


try:

    with open(filename, 'r') as file:

        text = file.read()


        lines = text.split('\n')

        number_of_lines = len(lines)


        words = text.split()

        number_of_words = len(words)


        number_of_characters = len(text)


        print("Number of lines:", number_of_lines)

        print("Number of words:", number_of_words)

        print("Number of characters:", number_of_characters)


except FileNotFoundError:

    print("File not found. Please make sure the file exists.")


6. Write a python program to create and to read records in binary file with  student name and marks of six subjects.


import pickle


def create_student_records():

    students = []


    n = int(input("How many student records do you want to enter? "))

    

    for i in range(n):

        print("\nEnter details for Student:",i+1)

        name = input("Name: ")

        marks = []

        for j in range(6):

            mark = float(input("Enter marks for Subject:"+str(j+1)))

            marks.append(mark)

        

        student = {'name': name, 'marks': marks}

        students.append(student)

    

    with open("students.dat", "wb") as file:

        pickle.dump(students, file)


    print("\nStudent records saved successfully!\n")


def read_student_records():

    try:

        with open("students.dat", "rb") as file:

            students = pickle.load(file)

            print("Student Records from File:\n")

            for student in students:

                print("Name:",student['name'])

                print("Marks:", student['marks'])

                print("Total:",sum(student['marks']))

                print("-" * 30)

    except FileNotFoundError:

        print("File not found. Please create records first.")


while True:

    print("\n1. Create Student Records")

    print("2. Read Student Records")

    print("3. Exit")

    choice = int(input("Enter your choice (1-3): "))


    if choice == 1:

        create_student_records()

    elif choice == 2:

        read_student_records()

    elif choice == 3:

        print("Exiting program.")

        break

    else:

        print("Invalid choice. Please enter 1, 2, or 3.")


7. Write a python program to copy the records of the students having percentage 90 and above from the binary file into another file. 


import pickle

students = [

    {"name": "Raju", "percentage": 95},

    {"name": "Amruth", "percentage": 88},

    {"name": "Rakesh", "percentage": 91},

    {"name": "Swaroop", "percentage": 76},

    {"name": "Krishna", "percentage": 90}

]


with open("students.dat", "wb") as file:

    for student in students:

        pickle.dump(student, file)


print("All student records saved in 'students.dat'.")


with open("students.dat", "rb") as infile, open("top_students.dat", "wb") as outfile:

    try:

        while True:

            student = pickle.load(infile)

            if student["percentage"] >= 90:

                pickle.dump(student, outfile)

    except EOFError:

        pass


print("Students with 90% and above copied to 'top_students.dat'.")


with open("top_students.dat", "rb") as file:

    print("\nStudents with 90% and above:")

    try:

        while True:

            student = pickle.load(file)

            print(student)

    except EOFError:

        pass


8.  Write a python program using function to sort the elements of a list using bubble sort method 


def bubblesort(numList):

    n = len(numList)

    i = 0

    while i < n:

        j = 0

        while j < n - i - 1:

            if numList[j] > numList[j + 1]:

                numList[j], numList[j + 1] = numList[j + 1], numList[j]

            j += 1

        i += 1


numList = [8, 7, 13, 1, -9, 4]


print("The original list is:", numList)


bubblesort(numList)


print("The sorted list is:", numList)



9. Write a python program using function to sort the elements of a list using selection sort method


def selectionsort(numList):

    n = len(numList)

    i = 0

    while i < n:

        min = i

        flag = 0  # Flag to check if a smaller element is found

        j = i + 1

        while j < n:

            if numList[j] < numList[min]:

                min = j

                flag = 1  # Smaller element found, set flag to True

            j += 1

        if flag==1:

            numList[i], numList[min] = numList[min], numList[i]

        i += 1


numList = [8, 7, 13, 1, -9, 4]


print("Original list:", numList)


selectionsort(numList)


print("Sorted list:", numList)



10. Write a python program using function to sort the elements of a list using insertion sort 

method 


def insertionsort(numList):

    n=len(numList)

    i = 1

    while i < n:

        temp = numList[i]

        j = i-1


        while j >= 0 and numList[j ] > temp:

            numList[j+1] = numList[j]

            j -= 1


        numList[j+1] = temp

        i += 1


numbers = [8, 7, 13, 1, -9, 4]

print("Original list:", numbers)


insertionsort(numbers)


print("Sorted list:  ", numbers)


11. Write a python program using function to search an element in a list using linear search method 


def linearsearch(numList, key):

    n=len(numList)

    index = 0

    while index < n:

        if numList[index] == key:

            return index + 1 

        else:

            index = index+1

    return -1


numList = [10, 25, 30, 45, 50, 65, 70]


key = int(input("Enter the number you want to search: "))


result = linearsearch(numList, key)


if result >= 0:

    print("The number ",key," is found at position: ",result)

else:

    print("Search is unsuccessful")


12. Write a python program using function to search an element in a list using binary search method.


def binarysearch(numList, key):

    n=len(numList)

    first = 0

    last = n - 1


    while first <= last:

        mid = (first + last) // 2  

        

        if numList[mid] == key:

            return mid + 1  

        elif numList[mid] > key:

            last = mid - 1  

        else:

            first = mid + 1  


    return -1  


numList = [1, 3, 5, 7, 9, 11, 13, 15, 17, 19]


key = int(input("Enter the number to search: "))


result = binarysearch(numList, key)


if result >= 0:

    print("Number found at position ",result)

else:

    print("Number not found in the list.")


13. Write a python program to add and display elements from a stack using list 


stack = []


def push_element():

    element = input("Enter an element to add to the stack: ")

    stack.append(element)

    print(element, "has been added to the stack.")


def display_stack():

    if not stack:

        print("The stack is empty.")

    else:

        print("Stack elements are (top to bottom):")

        for item in reversed(stack):

            print(item)


while True:

    print("\n--- Stack Menu ---")

    print("1. Add (Push) Element")

    print("2. Display Stack")

    print("3. Exit")


    choice = int(input("Enter your choice (1/2/3): "))


    if choice == 1:

        push_element()

    elif choice == 2:

        display_stack()

    elif choice == 3:

        print("Exiting program.")

        break

    else:

        print("Invalid choice. Please enter 1, 2, or 3.")


14. Write a python program to add and display elements from a queue using list 


queue = []


def add_to_queue(element):

    queue.append(element)  


def display_queue():

    print("Elements in the queue are:")

    for item in queue:

        print(item)


add_to_queue(10)

add_to_queue(20)

add_to_queue(30)

add_to_queue(40)


display_queue()

SECTION - B

MYSQL PROGRAMS

B1) Create a table with the following fields and enter 10 records into the table. Entity Name: marks

 

Attribute name

Type

Size

Constraints

Rollno

Int

5

 

Sname

Varchar

15

Not null

sub1

Int

3

Between 0 and 100

sub2

Int

3

Between 0 and 100

sub3

Int

3

Between 0 and 100

sub4

Int

3

Between 0 and 100

sub5

Int

3

Between 0 and 100

sub6

Int

3

Between 0 and 100


(i)  List all the records

(ii)  Display the description of the table

(iii) Add the new attributes total and percent

(iv)  Calculate total and percentage of marks for all the students

(v)  List the students whose percentage of marks is more than 60%.

(vi)  List the students whose percentage is between 60 % and 85%.

  (vii) Arrange the students based on percentage of marks from highest to lowest.

create table marks(rollno int(5),

    -> sname varchar(15) not NULL,

    -> sub1 int(3) check(sub1 between 0 and 100),

    -> sub2 int(3) check(sub2 between 0 and 100),

    -> sub3 int(3) check(sub3 between 0 and 100),

    -> sub4 int(3) check(sub4 between 0 and 100),

    -> sub5 int(3) check(sub5 between 0 and 100),

    -> sub6 int(3) check(sub6 between 0 and 100));

 

insert into marks values(1,'Raju',98,99,95,85,75,85);

insert into marks values(2,'Ramesh',60,51,45,45,65,75);

insert into marks values(3,'Suresh',58,75,68,55,35,45);

insert into marks values(4,'Amogh',55,60,78,75,65,60);

insert into marks values(5,'Krishna',56,87,78,98,88,85);

insert into marks values(6,'Junaid',98,75,65,89,78,55);

insert into marks values(7,'Vikas',55,65,35,65,35,45);

insert into marks values(8,'Sumadhwa',65,53,54,50,52,65);

 insert into marks values(9,'Santosh',100,99,54,54,90,87);

insert into marks values(10,'Samarth',99,98,54,45,88,85);

(i) List all the records

select * from marks;


(ii) Display the description of the table


desc marks;


(iii) Add the new attributes total and percent

 alter table marks add(total int(3),percent float(7,2));


(iv) Calculate total and percentage of marks for all the students

update marks set total=sub1+sub2+sub3+sub4+sub5+sub6;

update marks set percent=total/6;


(v) List the students whose percentage of marks is more than 60%.

select sname,percent from marks where percent>=60;


(vi) List the students whose percentage is between 60 % and 85%.

select sname,percent from marks where percent between 60 and 85;


(vii) Arrange the students based on percentage of marks from highest to lowest.

select sname,percent from marks order by percent desc;


B2) Create a table for household Electricity bill with the following fields and enter 10 records.

Entity Name: BESCOM

Attribute name

Type

Size

Constraint

RRNO

Varchar

10

Primary key

CUSTNAME

Varchar

25

Not null

BILLDATE

DATE

 

 

UNITS

INT

4

 

1.    View the structure of table.

2.    List all the records

3.    Add a new field for bill amount in the name of billamt.

4.   
Compute the bill amount for each consumer as per the following rules.

a.  MINIMUM Amount                    Rs. 100

b.  For first 100 units                        Rs 7.50/Unit

c.  For the above 100 units               Rs. 8.50/Unit

5.    Display the maximum, minimum and total bill amount.

6.    List all the bills generated in a sorted order based on RRNO.

create table bescom(rrno varchar(10) primary key,

    -> custname varchar(25) not NULL,

    -> billdate date,

    -> units int(4));

insert into bescom values('e05','ganesh','2025-07-24',97);

insert into bescom values('e01','jagadish','2025-07-25',101);

insert into bescom values('e03','kajol','2025-07-26',151);

insert into bescom values('e02','rakhi','2025-07-27',200);

insert into bescom values('e07','rakshita','2025-07-28',201);

insert into bescom values('e06','raj','2025-07-29',145);

insert into bescom values('e08','rajkumar','2025-07-30',90);

insert into bescom values('e09','rajeshwari','2025-07-31',0);

insert into bescom values('e10','rajesh','2025-08-1',100);

insert into bescom values('e4','rakesh','2025-08-2',121);

1.    View the structure of table.



2.    List all the records



3.    Add a new field for bill amount in the name of billamt.

alter table bescome add billamt float(7,2);



4.    
Compute the bill amount for each consumer as per the following rules.

a.  MINIMUM Amount                    Rs. 100

b.  For first 100 units                        Rs 7.50/Unit

c.  For the above 100 units               Rs. 8.50/Unit

i.               update bescom set billamt = 100 + units * 7.50 where units <= 100;

ii.             
update bescom set billamt = 100 + (100 * 7.50) + (units - 100) * 8.50 where units > 100;



5.    Display the maximum, minimum and total bill amount.



6.    List all the bills generated in a sorted order based on RRNO.


B3) Create a table with the following details and enter 10 records into the table.

Entity Name: student

 

Attribute name

Type

Size

Constraint

Rollno

int

5

Primary key

Sname

Varchar

15

Not null

DOB

date

 

 

Gender

char

1

 

Combn

Varchar

5

 

Class

Char

6

 

(i)  List all the students

(ii)  List the students who are in BASC and CEBA combination.

(iii)  List only the combination by removing duplicate values.

(iv)  List the students alphabetically.

(v)  List the students alphabetically and class-wise.

(vi)  List the students who born in the month of June of any year.

(vii)  Count the number of students Gender-wise.

 create table student ( rollno int(5) primary key,

    -> sname varchar(15) not null,

    -> dob date,

    -> gender char(1), combn varchar(5),

    -> class varchar(6));

 insert into student values(1,'vinod','2007-02-05','m','basc','2A');

 insert into student values(2,'vinutha','2006-03-05','m','ceba','2B');

 insert into student values(3,'Aruna','2007-05-15','f','ceba','2A');

 insert into student values(4,'Bharat','2007-06-20','m','basc','2B');

 insert into student values(5,'Chetana','2007-01-19','f','ceba','2A');

insert into student values(6,'deepak','2007-06-23','m','basc','2B');

insert into student values(7,'sneha','2007-05-24','f','ceba','2C');

insert into student values(8,'rakshita','2007-05-23','f','basc','2C');

insert into student values(9,'raj','2007-05-19','m','ceba','2A');

insert into student values(10,'rajeshwari','2007-02-25','f','basc','2B');

(i)  List all the students



(ii)  List the students who are in BASC and CEBA combination.



(iii)  List only the combination by removing duplicate values.



(iv)  List the students alphabetically.



(v)  List the students alphabetically and class-wise.



(vi)  List the students who born in the month of June of any year.



(vii)  Count the number of students Gender-wise.


B4) Create a table with following fields and enter 10 records into the table.

 

Entity Name: Library

 

Attribute name

Type

Size

Constraint

Title

Varchar

75

Not null

Author

Varchar

60

 

Year

int

4

 

Category

Varchar

25

 

Price

float

7,2

 

Qty

Int

4

 

(i)  List all the books

(ii)  Calculate Amount by altering table with a new column ‘Amount’

(iii)  List the records of all those books price is between 400 and 900.

(iv)  List those records with no value in the attribute year .

(v)  List the names of the authors whose name starts with ‘C’ or ‘D’.

(vi)  List Title, year, category with category has word ‘science’.

(vii) 
List all those records whose year of publication is 2010 onwards with price is less than 750.

 create table student ( rollno int(5) primary key,

    -> sname varchar(15) not null,

    -> dob date,

    -> gender char(1), combn varchar(5),

    -> class varchar(6));

insert into library values('the quantum world','carl sagan',2005,'science',850,4);

insert into library values('deep space','david clark',2011,'astronomy',720.50,2);

insert into library values('data structure','charles babbage',2008,'computer science',645.25,6);

insert into library values('chemistry essentials','Dr lisa ray',2012,'chemistry science',540.25,5);

insert into library values('programming in c','dennis ritchie',2000,'computer programming',375.00,3);

insert into library values('artificial intelligence','elon musk',2020,'computer science',910.00,7);

insert into library values('biology made easy','closer jones',NULL,'life science',480.10,2);

insert into library values('dark matter','stephen hawking',2015,'physics',780.40,8);

insert into library values('coding for kids','diana prince',2022,'computer science',399.99,10);

insert into library values('the dna code','craig venter',2018,'genetics science',620.00,1);

(i)  List all the books



(ii)  Calculate Amount by altering table with a new column ‘Amount’

(a)  alter table library add(amount float(7,2));

(b)  update library set amount = price * qty;



(iii)  List the records of all those books price is between 400 and 900.



(iv)  List those records with no value in the attribute year .



(v)  List the names of the authors whose name starts with ‘C’ or ‘D’.



(vi)  List Title, year, category with category has word ‘science’.



(vii)  List all those records whose year of publication is 2010 onwards with price is less than 750.

2nd puc computer science lab manual | class 12 computer science lab programs 2nd puc computer science lab manual | class 12 computer science lab programs Reviewed by Vision Academy on June 22, 2025 Rating: 5

No comments:

CheckOut

Powered by Blogger.