How to terminate python code when i dont know the number of test cases?

Hey,

I just got to know about UVA online judge. While solving 3n+1 problem(link given), my output was right but it says time limit exceeded. I have tested many sample input in it and answer was right. I guess the problem is i dont know how many test cases are there. So the loop doesnot terminates.

Can anyone help me?

while True:
i,j=[int(x) for x in input().split()]
if j<i:
i,j=j,i
max=0
for num in range(i,j+1):
l=[num]
while num>1:
if num==1:
max=1
elif num%2==0:
num=num//2
else:
num=num*3+1
l.append(num)
if len(l)>max:
max=len(l)
print(i,j,max)

try:
    while True:
         #code
except:
    pass  
2 Likes

Thankyou!