School ICT Self Study

File Operations, Database Interaction, and Algorithm Efficiency

0

  1. What are the basic file operations in Python?

  2. Write a Python program to write a string to a file and read it back.

  3. How can Python connect to a MySQL database to retrieve data?

  4. What is sequential search, and when is it used?

  5. Write a Python program to implement bubble sort on a list of numbers.

Spread the love
Ruwan Suraweera Changed status to publish 2 days ago
0

Answers and Descriptions:

  1. Answer: Open, close, read, write, append.
    Description: These operations allow file handling in Python. open() accesses a file, read()/write()/append() manipulates content, and close() releases resources.

  2. Answer:

    Description: The program uses with to safely open a file, writes a string in write mode (β€œw”), and reads it back in read mode (β€œr”).

  3. Answer: Use the mysql.connector module to connect, execute SQL queries, and fetch data.
    Description: Example:

    This connects to a MySQL database, retrieves all records from the students table, and closes the connection.

  4. Answer: Sequential search checks each element in a list until the target is found or the list ends.
    Description: It’s simple but inefficient for large datasets, used when data is unsorted or small.

  5. Answer:

    Description: Bubble sort compares adjacent elements and swaps them if out of order, repeating until sorted. It’s simple but inefficient for large lists.

Spread the love
Ruwan Suraweera Changed status to publish 2 days ago
You are viewing 1 out of 1 answers, click here to view all answers.
Write your answer.