Practice

Search a Product File

MEDIUMFile Handling7 marks
File I/O questionproducts.txt is pre-loaded for you during grading.

The file products.txt already contains one product name per line. Read a search term from the user and output Found if that name appears in the file (ignore case), otherwise Not found.

Input: One product name. Output: Found or Not found.

Example:

Input:  pencil
Output: Found

Sample Test Cases

Test 1: Match ignoring case
products.txt
Pen
Pencil
Ruler
Inputs: pencil
Expected: Found
Test 2: Missing product
products.txt
Pen
Pencil
Ruler
Inputs: Book
Expected: Not found

Premium Question

This question needs a paid plan — upgrade, or join a class from a teacher who has one. You can read the description and sample tests, but grading is locked.

Sign in to get started