Friday, 23 July 2021

read, write/create, search, append, update & delete methods in Binary file 

 

Program




































































Output






































































program

#Menu Driven program to perform all the operations

#on a Binary file....

import pickle

def write():

    f=open("StudentDetails.dat","wb")

    record=[]

    while True:

        rno=int(input("Roll No:"))

        name=input("Name:")

        marks=int(input("Marks:"))

        data=[rno,name,marks]

        record.append(data)

        ch=input("More(Y/N)?")

        if ch in 'Nn':

            break

    pickle.dump(record,f)

    print("Record Added..")

    f.close()


def read():

    print("Contents in a File...")

    f=open("StudentDetails.dat","rb")

    try:

        while True:

            s=pickle.load(f)

            print(s)

            for i in s:

                print(i)

    except Exception:

        f.close()


def append():

    f=open("StudentDetails.dat","rb+")

    print("Append data in a File..")

    Rec=pickle.load(f)

    while True:

        rno=int(input("Roll No:"))

        name=input("Name:")

        marks=int(input("Marks:"))

        data=[rno,name,marks]

        Rec.append(data)

        ch=input("More(Y/N)?")

        if ch in 'Nn':

            break

    f.seek(0)

    pickle.dump(Rec,f)

    print("Record Appended..")

    f.close()

            

def search():

    f=open("StudentDetails.dat","rb")

    r=int(input("Enter roll no to be searched:"))

    found=0

    try:

        while True:

            s=pickle.load(f)

            for i in s:

                if i[0]==r:

                    print(i)

                    found=1

                    break

    except EOFError:

        f.close()

    if found==0:

        print("Sorry...No record Found..")


def update():

    f=open("StudentDetails.dat","rb+")

    r=int(input("Enter roll no whose details to be updated:"))

    f.seek(0)

    try:

        while True:

            rpos=f.tell()

            s=pickle.load(f)

            print(s)

            for i in s:

                if i[0]==r:

                    i[1]=input("New Name:")

                    i[2]=int(input("Updated Marks:"))

                    f.seek(rpos)

                    pickle.dump(s,f)

                    break

    except Exception:

        f.close()

                

def delete():

    f=open("StudentDetails.dat","rb")

    s=pickle.load(f)

    f.close()

    r=int(input("Enter roll no to be deleted:"))

    f=open("StudentDetails.dat","wb")

    print(s)

    reclst=[]

    for i in s:

        if i[0]==r:

            continue

        reclst.append(i)

    pickle.dump(reclst,f)

    f.close()

        

#MainMenu

print("---------------------------------------------------")

print("1.Write Data in a Binary File..")

print("2.Read Data from a File..")

print("3.Append data in a File..")

print("4.Search Operation in a File..")

print("5.Update Data in a File..")

print("6.Delete Operation in a File..")

print("7.Exit..")

print("---------------------------------------------------")


while True:

    ch=int(input("Enter your choice:"))

    if ch==1:

        write()

    elif ch==2:

        read()

    elif ch==3:

        append()

    elif ch==4:

        search()

    elif ch==5:

        update()

    elif ch==6:

        delete()

    elif ch==7:

        break

                   

    



Sunday, 27 June 2021

12th class Python Program list 2021-22

                                    As per CBSE Practical List 2021-22

Term-1

 1. Read a text file line by line and display each word separated by a #.                             click here  Date:22-06-2021 

2. Read a text file and display the number of                                                                   vowels/consonants/uppercase/lowercase characters in the file.                                           Click here  Date:29-06-2021

3. Remove all the lines that contain the character 'a' in a file and write it to another file. Click here  Date:06-07-2021 

4. Create a binary file with name and roll number. Search for a given roll number and display the name, if not found display appropriate message.                                                    Click here  Date:13-07-2021

5. Create a binary file with roll number, name and marks. Input a roll number and update the marks. Click here Date:20-07-2021

 6. Write a random number generator that generates random numbers between 1 and 6 (simulates a dice). Click here Date: 27-07-2021

7. Write a Python program with function to count the number of lines in a text file ‘ 'STORY.TXT’ which is starting with an alphabet ‘A’ or 'a'.                                                                     Click here   date : 04-08-21

8. Write a Python program with method/function DISPLAYWORDS() to read lines from a text file STORY.TXT, and display those words, which are less than 4 characters.   Click Here  date : 11-08-21

9. Text Files Menu Driven Program: Click Here  date : 19-08-21

 Choice = 1. Read a text file line by line and display each word             

         separated by a '#'. 
           Choice = 2.Python program with function to count the number of lines 
              in a text file ‘ 'STORY.TXT’ which is starting with an alphabet ‘A’ or 'a'.
                Choice= 3. Python program with method/function DISPLAYWORDS() 
                  to read lines from a text file STORY.TXT, and display those words, 
                     which are less than 4 characters.

                  10. Text Files Menu Driven Program: Click Here  date: 26-08-21
                   Choice= 1. Remove all the lines that contain the character `a’ in a file and write it to another file. 
                    Choice= 2. Read a text file and display the number of vowels/                        consonants/ uppercase/ lowercase characters in the file.                                            

                    11. Create a CSV file by entering user-id and Password, read and search the password for given user-id.  Click here date: 04-09-21
                        12. Write a program to input the value of x and n and print the sum of the
                        series: x + x^2/2! - x^3/3! + x^4/4! + ............ x^n/n! click here   Date: 11-09-21

                        13. Determine whether a number is a perfect number, an armstrong number or a  palindrome.               click here  Date: 18-09-21 
                        14. Input a number and check if the number is a prime or composite number.                                       click here   Date: 23-09-21 
                        15. Display the terms of a Fibonacci series.         click here  Date: 30-09-21

                        Term-2
                        Data Structure

                        01 Stack Program 1 Write a python program to implement a stack using a list data-structure. Click Here (Reference Video: Click Here)   

                        02. Stack Program 2 Write a menu based python program to implement the the operations insert, delete, peek and display on stack(Member number, Member Name and Age).   Click Here
                         

                        03. Stack based program 3 Write a Python Program to implement a Stack for the book details (bookno,bookname). That is, each item node of the stack contains two types of information- a book number and its name. Implement all the operations of Stack.    Click Here

                        04. Write a Python program to implement a queue using a list data-structure.    Click Here    

                        05. Python Program for Binary Search( Iterative method) Click here


                        MySQL/SQL programmes

                        06. SQL Queries:-1 – Minimum 5 sets using one table / two tables. Click Here 

                        07. SQL Queries:-2 – Minimum 5 sets using one table / two tables. Click Here  

                        08. SQL Queries:-3- Create the following student table and answer the following queries. Click Here

                        Connectivity Programmes (Mysql with Python)

                        09. Find the total number of customers from each country in the table (customer ID, customer name, country) using group by( python interface through MYSQL). Click Here

                        10. INSERT, UPDATE, AND DELETE (PYTHON INTERFACE THROUGH MYSQL)ppt slides(RKS):ClickHer​e and Reference: INSERT, UPDATE, AND DELETE (PYTHON INTERFACE THROUGH  MYSQL)video: Click Here