Why does jupyter notebook run a cell with a syntax error?

Viewed 220

In this program is an intentional syntax error

import random
random.seed(16)

while True:
    n = random.randrange(1,101)
    print(n)
    if n < 30: break

if n==20:
    break

Run with !python test.py on google colab yields as expected

  File "test.py", line 10
    break
    ^
SyntaxError: 'break' outside loop

But run as a juypter notebook cell on google colab gives the output

47
61
62
37
54
30
58
1
  File "<ipython-input-43-35a4321b0145>", line 10
    break
    ^
SyntaxError: 'break' outside loop

In juypter notebook the program runs until leaving the while loop. My understanding was that the cell would be saved in a temporary file and executed using the standard python interpreter. Why is the execution different?

0 Answers
Related