First Negative
Completed
Read a line of integers and print the first negative one. If there is none, print none. Use break and a for-else.
Input
One line of integers.
Output
A number or none.
Example
Input
4 7 -2 9 -5
Output
-2
Editor
Python
Hints
The else of a for loop runs only if the loop finished without break.
Solution explanation
for … else avoids a separate "found" flag variable.
Show solution
for x in map(int, input().split()):
if x < 0:
print(x)
break
else:
print("none")