 <p>This is valid Python syntax when it is located in a module, but in the interactive interpreter you need to separate blocks of code with a blank line.</p> <p>The handy rule of thumb here is that you can't start a new block with <code>if</code>, <code>def</code>, <code>class</code>, <code>for</code>, <code>while</code>, <code>with</code>, or <code>try</code> unless you have the <code>&gt;&gt;&gt;</code> prompt.</p>