user6390718
user6390718

Reputation:

I don't know what the output code is. The compiler says there is an invalid character in identifier of line 3

b = 0
for a in range(0, 10, 2):
    b += a − 1 
print(a," ",b)

I am practicing on a past paper. Please help. And can someone please explain the break and continue functions.

Upvotes: 0

Views: 47

Answers (1)

Kasravnd
Kasravnd

Reputation: 107287

Character is not a correct python identifier for minus operator, you need - instead:

>>> 3 − 1
  File "<stdin>", line 1
    3 − 1
      ^
SyntaxError: invalid character in identifier
>>> 
>>> 3 - 1
2

It's actually a unicode with code point 8722:

>>> ord('−')
8722

Upvotes: 1

Related Questions