I want to run my program for total number of testcases from user input in hackerrank
Here in my code :
def sub_lists (l):
lists = [[]]
for i in range(len(l) 1):
for j in range(i):
lists.append(l[j: i])
return lists
# driver code
T=int(input())
while (T-- is not 0):
n,k=map(int,input().split())
l1 = list(int(num) for num in input().strip().split())[:n]
list_of_list=sub_lists(l1)
list_of_list=[sum(x) for x in list_of_list if sum(x)%k==0 and sum(x)>0 ]
print(len(list_of_list))
here T
is the user input;
CodePudding user response:
TestCasse=int(input())
while TestCase>0:
#your code
TestCode-=1
#or
for i in range(TestCase):
your code
CodePudding user response:
T
isn't used anywhere inside the loop, so there's no need to start counting at T
and decrement towards 0
.
All you need to do is to repeat the loop body T
times, so just use a for
loop:
for _ in range(T):
n,k=map(int,input().split())
... [rest of loop body]