This code run fine in my system, But here it show time limit Exceded
lis=[] x = input() while x: try: lis.append(int(x)) x= input() for item in lis: if (item==42): break print(item)
This is because you are storing data even when it’s not needed. Just don’t store anything in the array and check if the current obtained input is 42.