How do I run multiple Python test cases in a loop?

前端 未结 4 1602
忘了有多久
忘了有多久 2021-02-03 21:50

I am new to Python and trying to do something I do often in Ruby. Namely, iterating over a set of indices, using them as argument to function and comparing its results with an a

4条回答
  •  夕颜
    夕颜 (楼主)
    2021-02-03 22:23

    If Your question is regarding, when you are solving the problem on competitive places like hackerrank or anywhere else. If they have not provided their environment to run test cases in a loop.

    And locally if You are running code for python compiler It would be useful.

    you can simply use a while loop or range function of python.

    e.g:

    t = int(input("Enter Number of testcases"))
    type(t)
    
    while(t!=0):
    
        n = int(input("Enter number of data"))
        type(n)
    
        // Code logic or function Call
    
        t = t-1
    

提交回复
热议问题