Search code examples
pythonpython-3.xuser-inputtestcase

How to read input according to n number of test cases in python?


I came to a new type of problem in competitive programming where I have to read n lines of inputs according to the given test cases.

Example input format 👇 Example Input

So, how should I read this, can you please explain to me step-by-step? Waiting for a quick and effective solution.

Example Input 👇

2 - (no. of test cases)
STRING1
string2

Solution

  • It's the same as you solving one test case.

    The difference is you should put your logic to solve the problem in for loop for looping T times to handle multiple test cases.

    Example:

    def solve_the_problem(p):
      # Your logic here
    
    # Number of test cases
    T = input()
    for x in range(T):
      # Each input for test case
      p = input()
      solve_the_problem(p)