Neural Sync Active
Jan 2026 - Python - Week 9 - WEEK9-GrPA 2
Registry Synced
Jan 2026 - Python - Week 9 - WEEK9-GrPA 2
518 words
3 min read
WEEK9-GrPA 2
Course: Jan 2026 - Python
WEEK9-GrPA 2
Submission deadline has passed for this assignment
Due Apr 17, 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
2/2 Passed
Submitted on Apr 17, 2026 at 5:36 AM IST
Private Tests
5/5 Passed
Submitted on Apr 17, 2026 at 5:36 AM IST
Write a recursive function named linear that accepts the following arguments:
- P: a non-empty list of positive integers
- Q: a non-empty list of positive integers
- k: a positive integer
It should return True only if both the conditions given below are satisfied:
- P and Q are of same length.
- P[i]=k⋅Q[i], for every integer i in the range [0,len(P)−1], endpoints inclusive.
You do not have to accept input from the user or print output to the console. You just have to write the function definition.
Public Tests ( 2/2 )
Case 1
Input:
textpublic [2, 4, 6, 8] [1, 2, 3, 4] 2
Expected Output:
textTrue
Actual Output:
textTrue
Case 2
Input:
textpublic [10, 20, 30, 40, 50] [1, 2, 3, 4, 6] 10
Expected Output:
textFalse
Actual Output:
textFalse
Private Tests ( 5/5 )
Case 1
Input:
textprivate [10, 40, 30, 10, 20, 90, 80] [2, 8, 6, 2, 4, 18, 16] 5
Expected Output:
textTrue Good job! Your function is recursive
Actual Output:
textTrue Good job! Your function is recursive
Case 2
Input:
textprivate [1, 2, 3, 4, 5, 6, 7] [3, 6, 9, 12, 15, 18, 21] 3
Expected Output:
textFalse Good job! Your function is recursive
Actual Output:
textFalse Good job! Your function is recursive
Case 3
Input:
textprivate [1] [1] 1
Case 4
Input:
textprivate [10, 20, 30] [1, 2, 3, 4] 10
Case 5
Input:
textprivate [10, 100, 200, 300, 400] [2, 10, 20, 30, 40] 10
💻 IITM Official Solution
pythondef linear(P, Q, k): if len(P) != len(Q): return False if len(P) == 0: return True if P[0] / Q[0] != k: return False return linear(P[1: ], Q[1: ], k)
💻 My Submitted Code
pythondef linear(P, Q, k): """ A recursive function to determine if a list is scalar multiple of the other Arguments: P: list of integers Q: list of integers k: integer Return: result: bool """ # Length mismatch if len(P) != len(Q): return False # Base case if len(P) == 0: return True # Check current element if P[0] != k * Q[0]: return False # Recursive case return linear(P[1:], Q[1:], k)