IDLE can only do a single statement at once, i.e. in your case: A single line. So you have to paste in all lines ...
stackoverflow.com