0% found this document useful (0 votes)
8 views3 pages

Sodapdf

Uploaded by

sokkanathankmc
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
8 views3 pages

Sodapdf

Uploaded by

sokkanathankmc
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 3

---

# Python Program Documentation: ‘trios.csv‘ Student Search

INTRODUTCTION:
--------------
*This Python program allows you to create a CSV file containing student information and search for
specific entries in that file. The program includes the following features:

1. **Create**: Creates a CSV file with predefined student data.


2. **Search**: Allows the user to search for a student by entering a keyword or value. The program will
return all records that match the input

REQUREMENTS:
------------
*No external libraries are required for this program as it uses Python’s built-in ‘csv‘ module for
reading and writing CSV files.

CODE EXPLANATION:
---- ------------
*1. Importing Libraries

‘‘‘python
import csv
‘‘‘
This line imports the ‘csv‘ module, which provides functionality to read from and write to CSV files.

*2. ‘create()‘ Function

‘‘‘python
def create():
with open(’trios.csv’, ’w’, newline=’’) as fout:
writer = csv.writer(fout)
h = [’rno’, ’name’, ’clsss’, ’house’, ’game’, ’area’]
class_12th =[
[1, ’akash’,
’12th’, ’abhimanyu’, ’volly ball’, ’illuppur’],
[2, ’buvanan’, ’12th’, ’bheeshma’, ’foot ball’, ’viralimala’],
[3, ’deepak’, ’12th’, ’arjuna’, ’kabaddi’, ’illuppur’],
[4, ’dharshon’, ’12th’, ’bheeshma’, ’volly ball’, ’township’],
[5, ’dinesh kumar’, ’12th’, ’karna’, ’volly ball’, ’viralimalai’],
[6, ’rasik’, ’12th’, ’abhimanyu’, ’volly ball’, ’illuppur’],
[7, ’sakthi vel’, ’12th’, ’arjuna’, ’volly ball’, ’township’],
[8, ’sridher’, ’12th’, ’bheeshma’, ’kabaddi’, ’illuppur’],
[9, ’sudharshan’, ’12th’, ’karna’, ’volly ball’, ’illuppur’],
[10, ’tamil selvan’, ’12th’, ’abhimanyu’, ’kabaddi’, ’annavasal’],
[11, ’thio flus’, ’12th’, ’arjuna’, ’vollyball’, ’illuppur’],
[22, ’ashfaq’, ’12th’, ’abhimanyu’, ’vollyball’, ’annavasal’]
]

writer.writerows(class_12th)
print(’Created CSV file with titles:’, h)
‘‘‘
- The ‘create()‘ function generates a CSV file named ‘trios.csv‘ containing student data. Each row
represents a student with details like roll number, name, class, house, game, and area.
- The column titles (‘rno‘, ‘name‘, ‘clsss‘, ‘house‘, ‘game‘, ‘area‘) are written as the header.
- A list of student data is then written to the CSV file.
- After execution, the program will print a confirmation message indicating the file has been created.

* 3. ‘search()‘ FunctioN

‘‘‘python
def search():
ent = input(’Check the title and give an input to search: ’)
l = []

with open(’trios.csv’, ’r’, newline=’’) as fin:


reader = csv.reader(fin)
for i in reader:
l.append(i)

for j in l:
for k in j:
if str(k) == ent:
print(j)
‘‘‘

- The ‘search()‘ function prompts the user to input a keyword or value to search for in the CSV file.
- It reads the contents of ‘trios.csv‘ into a list, ‘l‘.
- Then, it loops through the list and searches each item (student record) for the input keyword.
- If the input matches any value in a student record, that entire record (the row) is printed.

* 4. Main Program Logic

‘‘‘python
create() # Creates the CSV file with student data

ch = ’yes’
while ch == ’yes’:
search() # Calls the search function
ch = input(’Do you want to continue? (yes or no): ’)
‘‘‘

- The program first calls the ‘create()‘ function to create the CSV file with student data.
- It then enters a loop, allowing the user to perform multiple searches. The loop continues as long as the
user responds with "yes" to the prompt: "Do you want to continue?"
- If the user enters anything other than "yes," the program ends.

## How to Run the Program

1. **Download/Clone the Repository**:


- Save the Python script to your computer (e.g., ‘student_search.py‘).

2. **Running the Program**:


- Open a terminal or command prompt and navigate to the folder where the script is saved.
- Run the program with the following command:
‘‘‘bash
python student_search.py
‘‘‘

3. **Input to Search**:
- The program will first create a CSV file (‘trios.csv‘) containing student data.
- You will then be prompted to enter a search term. The program will search for this term in the CSV file
and print any matching student records.

4. **Repeat or Exit**:
- After each search, you will be asked if you want to continue. Enter "yes" to perform another search, or
"no" to exit the program.

## Example Usage

1. **Program Execution**:

‘‘‘
created titles= [’rno’, ’name’, ’clsss’, ’house’, ’game’, ’area’]
Check the title and give an input to search: ’akash’
[’1’, ’akash’, ’12th’, ’abhimanyu’, ’volly ball’, ’illuppur’]

Do you want to continue? (yes or no): yes


Check the title and give an input to search: ’foot ball’
[’2’, ’buvanan’, ’12th’, ’bheeshma’, ’foot ball’, ’viralimala’]
Do you want to continue? (yes or no): no
‘‘‘

2. **Output Explanation**:
- After entering ‘’akash’‘, the program found the student record for Akash and printed it.
- After entering ‘’foot ball’‘, it found the record for Buvanan and printed it.
- The program then asked if you wanted to continue. When you chose "no", the program ended.

## Conclusion

This program provides a simple way to store and search for student information in a CSV file. It can be
extended to include more advanced features such as:
- Case-insensitive searching.
- Searching by multiple columns (e.g., searching by both game and area).
- Saving search results to a file.

You might also like