Simple Input - How to stop taking input when i reach end of file

How to stop taking input when i reach end of file? I used try except for now before typecasting because typecasting eof to int throws error and i used break to get out of the while loop then.
Here’s the code

Hey arjit,
How about this simple technique ;

sum =0
while sum>=0:
     x = int(input())
     sum+=x
     if (sum <0):
           break
     print(x, end= " ")

Thanks

I don’t think this would work in the case , when the sum doesn’t become negative , for eg. 4 1 3 5 2

Then it will keep printing. But in every test case there is a limit on time.

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.