How to use stdin inside a for loop in Python

1 Answer

0 votes
from sys import stdin
 
print("Enter numbers, 42 to exit:")
for line in stdin:
	n = int(line)
	if n == 42:
		break
	print(n)



'''
run:

STDIN
6
7
0
36785
42
 
Output:
Enter numbers, 42 to exit:
6
7
0
36785

'''

 



answered Apr 26 by avibootz

Related questions

2 answers 43 views
3 answers 63 views
1 answer 42 views
...