Neural Sync Active
Jan 2026 - Python - Week 8 - GrPA 2
Registry Synced
Jan 2026 - Python - Week 8 - GrPA 2
683 words
3 min read
Graded Assignment
Course: Jan 2026 - Python
GrPA 2
Submission deadline has passed for this assignment
Due Apr 08, 2026 at 11:59 PM IST
Instructions
Use "Test Run" to verify your code with public test cases.
Press "Submit" to have your assignment evaluated.
You can submit your assignment multiple times up until the deadline.
Make sure to submit your final code by the deadline to receive your score.
Summary
100 out of100
Score
Public Tests
3/3 Passed
Submitted on Apr 08, 2026 at 5:46 AM IST
Private Tests
5/5 Passed
Submitted on Apr 08, 2026 at 5:46 AM IST
**Change in eligibility criteria to write oppe2 exam: A5>=40/100 AND A6>=40/100 AND A7>=40/100 AND A8>=40/100. and becoming eligible to give the end term exam.
**
You are given two non-empty text files file1 and file2 that have f1 and f2 lines respectively. Each file is a collection of ten-digit phone numbers, one number per line. It is also known that 0<f1≤f2.
The following relations are defined on these two files:
- Subset: file1 is a subset of file2 if the phone number in the ith line of file1 is equal to the number in the ith line of file2, for 1≤i≤f1, and f1<f2.
- Equal: file1 is equal to file2 if the phone number in the ith line of file1 is equal to the number in the ith line of file2 for 1≤i≤f1, and f1=f2.
Write a function named relation that accepts these two text files as arguments. It should return the string Subset if file1 is a subset of file2. It should return Equal if file1 is equal to file2. If both these conditions are not satisfied, it should return the string No Relation.
(1) file1 and file2 are string variables that hold the names of the two files. For example, in the first test case, it is file1 = 'public_1_1.txt' and file2 = 'public_1_2.txt'.
(2) You do not have to accept input from the console or print the output to the console. You just have to write the function definition.
(3) The strings '9876543210' and '9876543210\n' are not the same, though the phone numbers are the same. So, strip the strings of all new lines using the strip method before checking for equality of two lines across the files.
Public Tests ( 3/3 )
Case 1
Input:
text100 public_1_1.txt public_1_2.txt
Expected Output:
textSubset
Actual Output:
textSubset
Case 2
Input:
text300 public_2_1.txt public_2_2.txt
Expected Output:
textNo Relation
Actual Output:
textNo Relation
Case 3
Input:
text500 public_3_1.txt public_3_2.txt
Expected Output:
textEqual
Actual Output:
textEqual
Private Tests ( 5/5 )
Case 1
Input:
text700 private_1_1.txt private_1_2.txt
Case 2
Input:
text900 private_2_1.txt private_2_2.txt
Case 3
Input:
text1100 private_3_1.txt private_3_2.txt
Case 4
Input:
text1300 private_4_1.txt private_4_2.txt
Case 5
Input:
text2341 private_5_1.txt private_5_2.txt
💻 IITM Official Solution
pythondef relation(file1, file2): f1 = open(file1, 'r') L1 = f1.readlines() for i in range(len(L1)): L1[i] = L1[i].strip() f1.close() f2 = open(file2, 'r') L2 = f2.readlines() for i in range(len(L2)): L2[i] = L2[i].strip() f2.close() if L1 == L2: return 'Equal' for i in range(len(L1)): if L1[i] != L2[i]: return 'No Relation' return 'Subset'
💻 My Submitted Code
pythondef relation(file1, file2): f1 = open(file1, 'r') f2 = open(file2, 'r') # Read all lines into lists for easier comparison lines1 = [line.strip() for line in f1.readlines()] lines2 = [line.strip() for line in f2.readlines()] f1.close() f2.close() count1 = len(lines1) count2 = len(lines2) # Check if lines in file1 match the corresponding lines in file2 # The constraint says count1 <= count2 is_match = True for i in range(count1): if lines1[i] != lines2[i]: is_match = False break if is_match: if count1 == count2: return 'Equal' else: return 'Subset' else: return 'No Relation'