Python program to check if the record is present in the file using its id.
Problem Description: We need to find the data from the file whose id is the same as the id entered by the user.
We will use the concepts of file handling in python.
Steps to check if the specific contents entered by the user of file:
- Step 1: Open the file in append mode using 'r'.
- Step 2: Get the input data from the user.
- Step 3: Compare the inputted data with data from file.
- Step 3.1: if data is present, print it.
- Step 3.2: if data is absent, print 'Record Not Found'.
Program to illustrate the solution of the problem
Output:
Here, we have opened data using 'r' mode. After this, we have requested the user for an input id to be searched for. Then we have compared the id's of data in the file. If any id matches, we will print its data otherwise print 'Record Not Found'.
need an explanation for this answer? contact us directly to get an explanation for this answer