I’m an absolute beginner, and I don’t understand why a is not incremented every time I run the code. It always prints a = 0 and a = 1.
JavaScript
x
9
1
a = 0
2
b = 2
3
4
print ("a = {}".format(a))
5
6
a = a + 1
7
8
print ("a = {}".format(a))
9
I’m working on Google Colab. Thanks in advance!
EDIT: I just noticed if I keep the two first lines on a separate block like this, the code does increment. Why??
Advertisement
Answer
Use two separate cells, one for declaring the variables and one for incrementing: